asxinyu/CefSharp.Common

去除默认代理
asxinyu authored at 2022-10-09 13:59:04
1a5e46c
Tree
1 Parent(s) c965c6c
Summary: 3 changed files with 4 additions and 27 deletions.
Modified +1 -0
Modified +0 -27
Modified +3 -0
Modified +1 -0
diff --git a/.gitignore b/.gitignore
index f70a8b4..4befff6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ bld/
 /BinCoreTest
 /BinXCodeTest
 /XUnitTest.XCode/TestEntity/Config
+*.txt
Modified +0 -27
diff --git a/NewLife.Spider/BaseSpider.cs b/NewLife.Spider/BaseSpider.cs
index d9e44d3..219b771 100644
--- a/NewLife.Spider/BaseSpider.cs
+++ b/NewLife.Spider/BaseSpider.cs
@@ -26,13 +26,6 @@ public abstract class BaseSpider
         browser.RequestHandler = _handler;
     }
 
-    private static async Task<String> GetProxyServer()
-    {
-        var str = await _httpClient.GetStringAsync("http://674246494.user.xiecaiyun.com/api/proxies?action=getText&key=NP980F72F7&count=1&word=&rand=true&norepeat=false&detail=false&ltime=0");
-        if (String.IsNullOrWhiteSpace(str)) throw new Exception("代理服务器获取失败");
-        return $"http://{str}".Trim();
-    }
-
     /// <summary></summary>
     /// <returns></returns>
     /// <exception cref="Exception"></exception>
@@ -50,33 +43,13 @@ public abstract class BaseSpider
                 isDone = true;
             }
         }
-
         using (CefResourceRequestHandler.CaptureAjax(handler))
         {
-            if (_changeProxy)
-            {
-                _changeProxy = false;
-
-                var proxy = await GetProxyServer();
-
-                await Cef.UIThreadTaskFactory.StartNew(delegate
-                {
-                    var rc = browser.GetBrowser().GetHost().RequestContext;  //获取 Request 上下文
-                    var dict = new Dictionary<String, Object> { { "mode", "fixed_servers" }, { "server", proxy } };
-
-                    if (!rc.SetPreference("proxy", dict, out var error))
-                        throw new Exception(error);
-                });
-            }
-
             await browser.LoadUrlAsync(desUrl);
-
             await Task.Delay(delayms);
-
             //TODO:可能有其他操作JS的任务
             OtherOperate();
         }
-
         if (!isDone) XTrace.WriteLine($"没有获取到数据");
     }
 
Modified +3 -0
diff --git a/NewLife.Spider/NewLife.Spider.csproj b/NewLife.Spider/NewLife.Spider.csproj
index cef6eb9..84ce2f6 100644
--- a/NewLife.Spider/NewLife.Spider.csproj
+++ b/NewLife.Spider/NewLife.Spider.csproj
@@ -36,6 +36,9 @@
     <PackageReadmeFile>Readme.MD</PackageReadmeFile>
   </PropertyGroup>
   <ItemGroup>
+    <None Remove="BaseSpider.txt" />
+  </ItemGroup>
+  <ItemGroup>
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>