4 回答
TA贡献1853条经验 获得超18个赞
这样的事情怎么样
PROXY = "149.215.113.110:70"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"noProxy":None,
"proxyType":"MANUAL",
"class":"org.openqa.selenium.Proxy",
"autodetect":False
}
# you have to use remote, otherwise you'll have to code it yourself in python to
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.FIREFOX)
TA贡献1784条经验 获得超8个赞
我的解决方案:
def my_proxy(PROXY_HOST,PROXY_PORT):
fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
print PROXY_PORT
print PROXY_HOST
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http",PROXY_HOST)
fp.set_preference("network.proxy.http_port",int(PROXY_PORT))
fp.set_preference("general.useragent.override","whater_useragent")
fp.update_preferences()
return webdriver.Firefox(firefox_profile=fp)
然后调用您的代码:
my_proxy(PROXY_HOST,PROXY_PORT)
我在此代码中遇到了问题,因为我将字符串作为端口#传递了:
PROXY_PORT="31280"
这个很重要:
int("31280")
您必须传递一个整数而不是一个字符串,否则您的Firefox配置文件将不会被设置为正确的端口,并且通过代理的连接将不起作用。
添加回答
举报