代理:Selenium + Python、Firefox [英] Proxy: Selenium + Python, Firefox
本文介绍了代理:Selenium + Python、Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 Python 中 Selenium 启动的 Firefox 流量重定向到代理?我已经使用了网络上建议的解决方案,但它们不起作用!
How can I redirect the traffic of Firefox launched by Selenium in Python to a proxy? I have used the solutions suggested on the web but they don't work!
我已经尝试过:
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "54.213.66.208")
profile.set_preference("network.proxy.http_port", 80)
profile.update_preferences()
driver = webdriver.Firefox(profile)
推荐答案
需要导入以下内容:
from selenium.webdriver.common.proxy import Proxy, ProxyType
然后设置代理:
myProxy = "xx.xx.xx.xx:xxxx"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': '' # set this value as desired
})
然后调用 webdriver.Firefox() 函数如下:
Then call the webdriver.Firefox() function as follows:
driver = webdriver.Firefox(proxy=proxy)
driver.get("http://www.google.com")
不记得我在哪里找到了这个解决方案,但它在某处.如果我再次找到它,肯定会提供一个链接.刚刚从我的代码中删除了这部分.
Don't remember where exactly I found this solution, but its out there somewhere. Will surely provide a link if I find it again. Just took this part out of my code.
这篇关于代理:Selenium + Python、Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文