带袜子的Firefox webdriver不起作用。怎么了?

时间:2016-02-08 10:14:35

标签: c# firefox selenium webdriver

我有我的代码的trubs。 我买了代理名单。名称是“具有绑定到IP地址的SOCKS 4/5代理列表”,它每隔一小时更新一次。 所以,我从这个txt文件中取出第一行,粘贴到我的代码中,但是不起作用! 代码是:

        FirefoxProfile profile = new FirefoxProfile();
        profile.SetPreference("network.proxy.socks", "46.161.62.165");
        profile.SetPreference("network.proxy.socks_port", 1085);

        profile.SetPreference("network.proxy.type", 1);         // this is used to set proxy configuration to manual, after which firefox considers the //proxy set above

        FirefoxDriver driver = new FirefoxDriver(profile);
        driver.Navigate().GoToUrl(@"http://whatismyipaddress.com");

我也尝试了另一种方式:

    FirefoxProfile profile = new FirefoxProfile();
    String PROXY = "46.161.62.165:1080";
    OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
    proxy.SocksProxy = PROXY;
    profile.SetProxyPreferences(proxy);
    int timeoutSeconds = 1800;
    FirefoxDriver Driver = new FirefoxDriver(new FirefoxBinary(), profile, new TimeSpan(0, 0, 0, timeoutSeconds));
    Driver.Navigate().GoToUrl(@"http://whatismyipaddress.com");

但它不起作用。 请帮我。 一些有趣的事实:这个代理真实,它应该工作。 我还有另一个清单。有:

List of HTTP/HTTPS proxies with authentication by password:
TXT  CSV
List of SOCKS 4/5 proxies with authentication by password:
TXT  CSV
List of HTTP/HTTPS proxies with a binding to IP address:
TXT  CSV
List of SOCKS 4/5 proxies with a binding to IP address:

如何使用登录名和密码进行操作? 感谢所有人和所有人。 和平。

2 个答案:

答案 0 :(得分:1)

我没有使用SOCKS,但我认为它应该是这样的:

private FirefoxDriver _CreateFirefoxDriver(string socksProxy)
{
    if (string.IsNullOrEmpty(socksProxy))
    {
        return new FirefoxDriver();
    }

    var caps = new DesiredCapabilities();
    caps.SetCapability(CapabilityType.Proxy, new Proxy { SocksProxy = socksProxy });
    return new FirefoxDriver(caps);
}

答案 1 :(得分:1)

Documentation以这种方式显示(这是java代码,但同样适用于C#)

String PROXY = "46.161.62.165:1085";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setSocksProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);