|
@@ -275,8 +275,13 @@ namespace FCS.Common
|
|
|
/// <returns></returns>
|
|
|
public static HtmlDocument GetHtmlHtmlDocument(HtmlParameterDTO model)
|
|
|
{
|
|
|
+ var html = string.Empty;
|
|
|
+ if (model.IsWebClient)
|
|
|
+ html = GetHtmlByWebClient(model);
|
|
|
+ else
|
|
|
+ html = GetHtmlByIP(model);
|
|
|
var doc = new HtmlDocument();
|
|
|
- doc.LoadHtml(GetHtmlByIP(model));
|
|
|
+ doc.LoadHtml(html);
|
|
|
return doc;
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -286,7 +291,10 @@ namespace FCS.Common
|
|
|
/// <returns></returns>
|
|
|
public static string GetHtmlString(HtmlParameterDTO model)
|
|
|
{
|
|
|
- return GetHtmlByIP(model);
|
|
|
+ if (model.IsWebClient)
|
|
|
+ return GetHtmlByWebClient(model);
|
|
|
+ else
|
|
|
+ return GetHtmlByIP(model);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -304,7 +312,7 @@ namespace FCS.Common
|
|
|
var httpItem = new HttpItem();
|
|
|
lock (locker)
|
|
|
{
|
|
|
- httpItem=Mapper<HttpItem>(model);
|
|
|
+ httpItem = Mapper<HttpItem>(model);
|
|
|
httpItem.WebProxy = new WebProxy(ip);
|
|
|
}
|
|
|
var html = new HttpHelper().GetHtml(httpItem);
|
|
@@ -319,7 +327,7 @@ namespace FCS.Common
|
|
|
|| (html.Html.Contains("The requested URL could not be retrieved") && html.Html.ToLower().Contains("could not be retrieved"))
|
|
|
|| html.Html.Contains("缓存访问被拒绝")
|
|
|
|| html.Html.Contains("无效用户")
|
|
|
- || (!model.Title.IsEmpty() && !html.Html.Contains(model.Title)))
|
|
|
+ || (!model.Title.IsEmpty() && !html.Html.Contains(model.Title)))
|
|
|
{
|
|
|
if (html.Html.ToLower().Contains("exception report"))
|
|
|
{
|
|
@@ -406,6 +414,20 @@ namespace FCS.Common
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ #region WebClient请求
|
|
|
+ private static string GetHtmlByWebClient(HtmlParameterDTO model)
|
|
|
+ {
|
|
|
+ using (var webClient = new WebClient())
|
|
|
+ {
|
|
|
+ webClient.Credentials = CredentialCache.DefaultCredentials;
|
|
|
+ byte[] pageDate = webClient.DownloadData(model.Url);
|
|
|
+ var content = Encoding.UTF8.GetString(pageDate);
|
|
|
+ webClient.Dispose();
|
|
|
+ return content;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region lg
|
|
|
|
|
|
/// <summary>
|
|
@@ -578,23 +600,23 @@ namespace FCS.Common
|
|
|
int num = 0;
|
|
|
//比赛
|
|
|
ss.ForEach(async p1 =>
|
|
|
- {
|
|
|
- await Task.Run(() =>
|
|
|
- {
|
|
|
- var html = new HttpHelper().GetHtml(new HttpItem
|
|
|
- {
|
|
|
- Url = url,
|
|
|
- Method = method,
|
|
|
- WebProxy = new WebProxy(p + ":" + p1)
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
- lock (g)
|
|
|
- {
|
|
|
- num++;
|
|
|
- Monitor.Pulse(g); //完成,通知等待队列,告知已完,执行下一个。
|
|
|
- }
|
|
|
- });
|
|
|
+ {
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ var html = new HttpHelper().GetHtml(new HttpItem
|
|
|
+ {
|
|
|
+ Url = url,
|
|
|
+ Method = method,
|
|
|
+ WebProxy = new WebProxy(p + ":" + p1)
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ lock (g)
|
|
|
+ {
|
|
|
+ num++;
|
|
|
+ Monitor.Pulse(g); //完成,通知等待队列,告知已完,执行下一个。
|
|
|
+ }
|
|
|
+ });
|
|
|
lock (g)
|
|
|
{
|
|
|
while (num < max)
|
|
@@ -753,11 +775,11 @@ namespace FCS.Common
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void LogBD(string content, string pathName = "",string directoryName="Log")
|
|
|
+ public static void LogBD(string content, string pathName = "", string directoryName = "Log")
|
|
|
{
|
|
|
if (pathName.IsEmpty())
|
|
|
pathName = content;
|
|
|
- var path = AppDomain.CurrentDomain.BaseDirectory + "/"+ directoryName;
|
|
|
+ var path = AppDomain.CurrentDomain.BaseDirectory + "/" + directoryName;
|
|
|
CreateDirectory(path);
|
|
|
path += $"/{DateTime.Now.ToString("yyyyMMdd")}";
|
|
|
CreateDirectory(path);
|
|
@@ -778,6 +800,25 @@ namespace FCS.Common
|
|
|
{
|
|
|
return AutoMapper.Mapper.DynamicMap<T>(data);
|
|
|
}
|
|
|
+
|
|
|
+ //获取外网IP
|
|
|
+ public static string GetExternalIP()
|
|
|
+ {
|
|
|
+ using (var webClient = new WebClient())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ webClient.Credentials = CredentialCache.DefaultCredentials;
|
|
|
+ byte[] pageDate = webClient.DownloadData("http://pv.sohu.com/cityjson?ie=utf-8");
|
|
|
+ String ip = Encoding.UTF8.GetString(pageDate); webClient.Dispose();
|
|
|
+ Match rebool = Regex.Match(ip, @"\d{2,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"); return rebool.Value;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class AsyncSemaphore
|