![](/img/trans.png)
[英]How to set up selenium 3.0, getting error “The geckodriver.exe file does not exist…” in c#
[英]Set up proxy on selenium geckodriver
我在向 geckodriver selenium 程序添加代理支持时遇到问题。
var proxy = new Proxy();
if (useproxies == true)
{
if (proxytype) //True = SOCKS5
{
/*var proxy = proxies[proxyindex];
profile.SetPreference("network.proxy.type", 1);
profile.SetPreference("network.proxy.socks", proxy.Split(':')[0]);
profile.SetPreference("network.proxy.socks_port", proxy.Split(':')[1]);
*/
proxy.SocksProxy = proxies[proxyindex];
if (proxyindex >= (proxies.Count - 1)) { proxyindex = 0; } else { proxyindex++; }
}
else //False = HTTP
{
proxy.HttpProxy = proxies[proxyindex];
if (proxyindex >= (proxies.Count - 1)) { proxyindex = 0; } else { proxyindex++; }
}
}
//user agent
profile.SetPreference("general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0");
//start
options.Proxy = proxy;
options.Profile = profile;
driver = new FirefoxDriver(options);
但这不起作用,我已经尝试了很多方法,但没有一个对我有用。 任何人都知道如何做到这一点? 第一次使用 geckodriver,我总是使用 chromedriver。
编辑:为了回答@AtachiShadow,问题仍然存在。
var profile = new FirefoxProfile();
var options = new FirefoxOptions();
//proxy
if (useproxies == true)
{
if (proxytype) //True = SOCKS5 | False = HTTP
{
try
{
profile.SetPreference("network.proxy.type", 1);
profile.SetPreference("network.proxy.socks", proxies[proxyindex].Split(':')[0]);
profile.SetPreference("network.proxy.socks_port", proxies[proxyindex].Split(':')[1]);
profile.SetPreference("network.proxy.socks_version", 5);
if (proxyindex >= (proxies.Count - 1)) { proxyindex = 0; } else { proxyindex++; }
}
catch
{
WriteConsole("Proxies.txt is bad... Exiting.");
Console.Read();
Environment.Exit(0);
}
}
else
{
try
{
if (proxyindex >= (proxies.Count - 1)) { proxyindex = 0; } else { proxyindex++; }
}
catch
{
WriteConsole("Proxies.txt is bad... Exiting.");
Console.Read();
Environment.Exit(0);
}
}
}
//user agent
profile.SetPreference("general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0");
//start
options.Profile = profile;
driver = new FirefoxDriver(options);
与您的建议相同的问题
我使用以下命令在浏览器中启用代理袜子(这是 Python 3 代码):
fp = webdriver.FirefoxProfile(ub_profile)
fp.set_preference('network.proxy.type', 1) # int
fp.set_preference('network.proxy.socks', '111.11.11.1') # string
fp.set_preference('network.proxy.socks_port', 12345) # int
fp.set_preference('network.proxy.socks_version', 4) # int
browser = webdriver.Firefox(firefox_profile=fp)
并且您的代码有所不同。 您可能没有指明您拥有哪个版本的代理袜子:
fp.set_preference('network.proxy.socks_version', 4) # When you have proxy version 4
或者
fp.set_preference('network.proxy.socks_version', 5) # When you have proxy version 5
然而,我通过.FirefoxProfile()
而不是通过.Options()
启用代理。
像这样试试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.