2016-02-08 37 views
0

我有我的代碼trubs。 我買了代理列表。名稱是「帶有綁定到IP地址的SOCKS 4/5代理列表」,它的每一小時都是更新。 因此,我從這個txt文件中取第一行,粘貼到我的代碼中,但不起作用! 代碼是:帶有襪子的Firefox webdriver不起作用。怎麼了?

 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: 

我怎樣才能做到這一點與登錄名和密碼? 感謝所有人和所有人。 和平。

回答

1

我沒有使用過襪子,但我想應該是這樣的:

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

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); 
相關問題