【发布时间】:2019-09-05 23:28:56
【问题描述】:
我在为我的 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);
你的建议也有同样的问题
【问题讨论】:
标签: c# selenium geckodriver