Mic*_*ina 10 python firefox proxy selenium
如何将Selenium在Python中启动的Firefox流量重定向到代理?我使用过网络上建议的解决方案,但它们不起作用!
我试过了:
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)
ami*_*tta 15
您需要导入以下内容:
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()函数,如下所示:
driver = webdriver.Firefox(proxy=proxy)
driver.get("http://www.google.com")
不记得我在哪里找到了这个解决方案,但它在某处.如果再找到它,肯定会提供一个链接.刚从我的代码中取出这部分.
您的问题出在驱动程序init上.尝试webdriver = webdriver.Firefox(firefox_profile=profile)所有其他代码都没问题,你也可以删除profile.update_preferences()行.
我用2分钟的谷歌搜索找到了你的解决方案.你花了多少时间等待?:d
你的问题是你可能从其他语言中读取代码而不是Python.替换webdriver.Firefox(profile)为webdriver.Firefox(firefox_profile=profile).
你的代码应该是:
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(firefox_profile=profile)
对于Firefox / Geckodriver,请尝试以下操作:
proxy = "212.66.117.168:41258"
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": proxy,
    "ftpProxy": proxy,
    "sslProxy": proxy
}
driver = webdriver.Firefox(capabilities=firefox_capabilities)
对于Chrome,您可以使用:
proxy = "212.66.117.168:41258"
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = proxy
prox.socks_proxy = proxy
prox.ssl_proxy = proxy
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)
| 归档时间: | 
 | 
| 查看次数: | 23997 次 | 
| 最近记录: |