selenium设置代理后无法打开网页
在用selenium打开chrome浏览器的网页时,使用如下代码设置了代理IPfrom 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
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
GetHandleVerifier
GetHandleVerifier
GetHandleVerifier
GetHandleVerifier
Ordinal0
Ordinal0
Ordinal0
Ordinal0
BaseThreadInitThunk
RtlGetFullPathName_UEx
RtlGetFullPathName_UEx 已经试过将 "--proxy-server=http://" 参数设置成 "-proxy-server=http://" 或者去掉 "http://" 都不行想要达到的结果想要知道怎么正确设置selenium的代理IP
参考下这个链接https://www.gxlcms.com/python-359377.html 检查代理服务器 不清楚 配置是否能够正常联网
页:
[1]