【发布时间】:2019-10-09 03:14:14
【问题描述】:
由于一些限制,我必须使用代理来访问一个特定的网站。为此,我订阅了一项付费代理服务,并尝试访问该网站,它成功了。但是,要使用 Google Chrome 的代理服务,我必须从 Windows Edge 浏览器配置代理设置,因此代理设置会影响我 PC 中的所有网络浏览器,这是我不想要的;因为,除了那个特定的网站,我可以直接使用我的 ISP 访问所有其他网站,没有任何问题。我尝试了以下 C# 代码,看看我是否只能在底层 Chromium 会话期间使用代理设置访问“WhatIsMyIP”网站。
private static readonly LaunchOptions puppeteer_launchOptions = new LaunchOptions
{
Headless = false,
IgnoreHTTPSErrors = true,
Args = new[] {
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-certificate-errors",
$"--proxy-server='1.2.3.4:5678'",
},
};
static async Task Main()
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
_browser = await Puppeteer.LaunchAsync(puppeteer_launchOptions);
Page _page = await _browser.NewPageAsync();
await _page.SetViewportAsync((new ViewPortOptions { Width = 1920, Height = 938 }));
_page.DefaultNavigationTimeout = 100000;
await _page.GoToAsync("https://www.whatismyip.com/");
await _page.WaitForTimeoutAsync(2000);
Console.WriteLine("My Public IP is:");
}
但是,我的代码不起作用,我收到错误消息:PuppeteerSharp.NavigationException HResult=0x80131500 Message=net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/ https://www.whatismyip.com/ Source=PuppeteerSharp StackTrace: at PuppeteerSharp.FrameManager.d__42.MoveNext( ) 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() ` 1.GetResult() 在 ProxyWhatIsMyIP.Program.d__3.MoveNext() 在 C:\DualDataLiveBet\BetFairProxy\ProxyWhatIsMyIP\ProxyWhatIsMyIP\Program.cs:line 31
内部异常 1:NavigationException: net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/
但是,如果我在 Microsoft Edge 浏览器中更改了全局代理设置,并在我的 C# 代码中删除了代理设置,它就可以工作了。以下是工作代码:
using PuppeteerSharp;
using System;
using System.Threading.Tasks;
namespace ProxyWhatIsMyIP
{
class Program
{
public static Browser _browser;
private static readonly LaunchOptions puppeteer_launchOptions = new LaunchOptions
{
Headless = false,
IgnoreHTTPSErrors = true,
Args = new[] {
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-certificate-errors",
},
};
static async Task Main()
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
_browser = await Puppeteer.LaunchAsync(puppeteer_launchOptions);
Page _page = await _browser.NewPageAsync();
await _page.SetViewportAsync((new ViewPortOptions { Width = 1920, Height = 938 }));
_page.DefaultNavigationTimeout = 100000;
await _page.GoToAsync("https://www.whatismyip.com/");
await _page.WaitForTimeoutAsync(2000);
Console.WriteLine("My Public IP is:");
}
}
但这不是我想要的。我只想在这个 Chromium 会话期间使用代理,但保持全局代理设置不变(不要在我的 PC 中使用任何代理。)请告知我该怎么做?顺便说一句,我正在使用 Visual Studio 2019 版本 16.3.2 和 PuppeteerSharp 1.20.0,目标是 .NET Core 3.0。我的电脑在应用了最新更新的 Windows 10(版本 1903)上运行。谢谢,
【问题讨论】:
-
您的代理提供商是什么?
-
我遇到了同样的问题,代理需要凭据*,但似乎找不到解决方案。有人有什么建议或技巧吗?
-
你试过去掉引号吗?像这样:--proxy-server=1.2.3.4:5678
标签: c# google-chrome proxy microsoft-edge puppeteer-sharp