在C#中,我试图在firefox中设置具有身份验证的袜子代理。
这不起作用
Proxy proxy = new Proxy();
proxy.SocksProxy = sProxyIP + ":" + sProxyPort;
proxy.SocksUserName = sProxyUser;
proxy.SocksPassword = sProxyPass;
options.Proxy = proxy;
_driver = new FirefoxDriver(service, options);
这也不起作用
profile.SetPreference("network.proxy.socks", sProxyUser + ":" + sProxyPass + "@" + sProxyIP + ":" + sProxyPort);
profile.SetPreference("network.proxy.socks_port", sProxyPort);
我该如何解决?
据我所知,您无法使用Firefox以这种方式进行操作。您需要添加一个新的Firefox配置文件,然后将其与Selenium一起使用。在此配置文件上,您需要保存代理信息并保存用户名和密码。
您可以按照此步骤link设置Firefox配置文件。这样就很容易完成这项工作。我使用该代码:
FirefoxProfile profile = new FirefoxProfile(pathToProfile);
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
driver = new FirefoxDriver(options);
然后,您将不得不取消显示有关用户名和密码验证的警报。您可以使用两种方法来做到这一点。第一个是以编程方式进行。像这样:
var alert = driver.SwitchTo().Alert();
alert.Accept();
另一种方法是从Firefox配置文件设置中执行此操作。