mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-29 12:43:16 +08:00
fixbugs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user