在用selenium打开chrome浏览器的网页时,使用如下代码设置了代理IP
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
ops = Options()
proxy = "223.96.90.216:8085"
print('--proxy-server=http://%s' % proxy)
ops.add_argument('--proxy-server=http://%s' % proxy) # 设置代理
driver = webdriver.Chrome(chrome_options=ops) # 创建实例
# driver.get("http://httpbin.org/get")
driver.get("http://www.baidu.com")
打开httpbin.org时可以看到IP已经变成了设置的代理IP
但是想要打开其他网页就失败了,比如百度都打不开
打开百度时的报错
Traceback (most recent call last):
File "d:/工作/pythonprogram/网页自动点击/proxy_test.py", line 15, in <module>
driver.get("http://www.baidu.com")
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 437, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CONNECTION_FAILED
(Session info: chrome=100.0.4896.60)
Stacktrace:
Backtrace:
Ordinal0 [0x01127413+2389011]
Ordinal0 [0x010B9F61+1941345]
Ordinal0 [0x00FAC658+837208]
Ordinal0 [0x00FA8F28+823080]
Ordinal0 [0x00F9E27D+778877]
Ordinal0 [0x00F9EE3D+781885]
Ordinal0 [0x00F9E48A+779402]
Ordinal0 [0x00F9DA86+776838]
Ordinal0 [0x00F9C995+772501]
Ordinal0 [0x00F9CE6D+773741]
Ordinal0 [0x00FADE5A+843354]
Ordinal0 [0x010049BD+1198525]
Ordinal0 [0x00FF414C+1130828]
Ordinal0 [0x01004302+1196802]
Ordinal0 [0x00FF3F66+1130342]
Ordinal0 [0x00FCE546+976198]
Ordinal0 [0x00FCF456+980054]
GetHandleVerifier [0x012D9632+1727522]
GetHandleVerifier [0x0138BA4D+2457661]
GetHandleVerifier [0x011BEB81+569713]
GetHandleVerifier [0x011BDD76+566118]
Ordinal0 [0x010C0B2B+1968939]
Ordinal0 [0x010C5988+1989000]
Ordinal0 [0x010C5A75+1989237]
Ordinal0 [0x010CECB1+2026673]
BaseThreadInitThunk [0x760A6739+25]
RtlGetFullPathName_UEx [0x77078E7F+1215]
RtlGetFullPathName_UEx [0x77078E4D+1165]
尝试过的方法
已经试过将 "--proxy-server=http://" 参数设置成 "-proxy-server=http://" 或者去掉 "http://" 都不行
想要达到的结果
想要知道怎么正确设置selenium的代理IP