如何使用Selenium设置专用代理? [英] How to Setup Private Proxy with Selenium?
本文介绍了如何使用Selenium设置专用代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我尝试了以下两种方法,在这两种情况下,Firefox都会正常启动 。
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyHost + proxyPort);
proxy.setSocksUsername(proxyUsername);
proxy.setSocksPassword(proxyPass);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(CapabilityType.PROXY,proxy);
WebDriver driver = new FirefoxDriver(cap);
driver.get(http://google.com);
我也尝试了以下方法:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(network.proxy.type,1);
profile.setPreference(network.proxy.http,proxyHost);
profile.setPreference(network.proxy.http_port,proxyPort);
profile.setPreference(network.proxy.http,user:pass@1.1.1.1);
profile.setPreference(network.proxy.http_port,proxyPort);
WebDriver driver = new FirefoxDriver(profile);
driver.get(http://google.com);
如何设置http专用代理(在Firefox中使用Selenium的用户名和密码)?
谢谢
proxy = Proxy({
'proxyType':ProxyType .MANUAL,
'httpProxy':PROXY_HOST,
'socksUsername':'name',
'socksPassword':'pass'
})
driver = webdriver.Firefox(proxy = proxy)
I've been trying for days to setup a private proxy (with authentication) in Selenium using Firefox. However, no matter what I do I'v been unsuccessful.
Currently, I have tried the following two approaches and in both cases Firefox launches normally without any proxy.
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyHost + proxyPort);
proxy.setSocksUsername(proxyUsername);
proxy.setSocksPassword(proxyPass);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
driver.get("http://google.com");
I have also tried the following:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", proxyHost);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.http", "user:pass@1.1.1.1");
profile.setPreference("network.proxy.http_port", proxyPort);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://google.com");
How can I setup http private proxies (with user name and password in Selenium with Firefox)?
I am using Java.
Thanks
解决方案
Find solution:
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': PROXY_HOST,
'socksUsername': 'name',
'socksPassword': 'pass'
})
driver = webdriver.Firefox(proxy=proxy)
这篇关于如何使用Selenium设置专用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文