尝试使用selenium的代理时,它返回以下错误:
Traceback (most recent call last):
File "tronio.py", line 1456, in <module>
task1()
File "tronio.py", line 74, in task1
driver1 = webdriver.Firefox(capabilities=desired_capability)
File "C:\Users\ninja_000\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 158, in __init__
keep_alive=True)
File "C:\Users\ninja_000\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\ninja_000\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\ninja_000\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\ninja_000\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: Invalid proxy configuration entry: httpProxyPort
我的代码是:
proxy = ip:port
hostport = proxy[proxy.find("@")+1:]
host = hostport[0:hostport.find(":")]
port = hostport[hostport.find(":")+1:]
if proxy:
desired_capability = webdriver.DesiredCapabilities.FIREFOX
desired_capability['proxy']={
"httpProxy":host,
"httpProxyPort": port
}
driver1 = webdriver.Firefox(capabilities=desired_capability)
帮助表示赞赏,在堆栈上的另一个教程中,代理是有效的,我已对其进行了测试。
答案 0 :(得分:0)
PROXY = getProxy()
if PROXY:
webdriver.DesiredCapabilities.FIREFOX['proxy']={
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"proxyType":"MANUAL"
}
driver1 = webdriver.Firefox()
wait = WebDriverWait(driver1, 1000000)
这对我有用,而且效果更好imo
答案 1 :(得分:0)
我也遇到了这个问题:在代理字符串中包含端口(无方案)有效。