This commit is contained in:
懒得勤快
2017-10-17 17:50:21 +08:00
parent 55c6c41786
commit bfb6c37927
2 changed files with 37 additions and 33 deletions
+22 -22
View File
@@ -302,37 +302,37 @@ namespace Masuit.Tools.Html
///<summary>
///3.1清除HTML标记
///</summary>
///<param name="Htmlstring">包括HTML的源码</param>
///<param name="htmlstring">包括HTML的源码</param>
///<returns>已经去除后的文字</returns>
public static string RemoveHtml(this string Htmlstring)
public static string RemoveHtml(this string htmlstring)
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase);
Htmlstring = regex.Replace(Htmlstring, "");
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
htmlstring = regex.Replace(htmlstring, "");
htmlstring = Regex.Replace(htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"-->", "", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
htmlstring = Regex.Replace(htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
htmlstring.Replace("<", "");
htmlstring.Replace(">", "");
htmlstring.Replace("\r\n", "");
return Htmlstring;
return htmlstring;
}
#endregion
+15 -11
View File
@@ -379,23 +379,27 @@ namespace Masuit.Tools.Net
/// <returns></returns>
public static string GetISP(this string ip)
{
using (var client = new HttpClient { BaseAddress = new Uri("http://ip.taobao.com") })
if (ip.MatchInetAddress())
{
try
using (var client = new HttpClient { BaseAddress = new Uri("http://ip.taobao.com") })
{
var result = client.GetStringAsync($"/service/getIpInfo.php?ip={ip}").Result;
TaobaoIP taobaoIp = JsonConvert.DeserializeObject<TaobaoIP>(result);
if (taobaoIp.Code == 0)
try
{
return taobaoIp.IpData.Isp;
var result = client.GetStringAsync($"/service/getIpInfo.php?ip={ip}").Result;
TaobaoIP taobaoIp = JsonConvert.DeserializeObject<TaobaoIP>(result);
if (taobaoIp.Code == 0)
{
return taobaoIp.IpData.Isp;
}
}
catch (Exception e)
{
}
}
catch (Exception e)
{
LogManager.Error(e);
}
return $"未能找到{ip}的ISP信息";
}
return $"未能找到{ip}的ISP信息";
return $"{ip}不是一个合法的IP";
}
#endregion