Python+selenium爬虫报错 ERROR:ssl_client_socket_impl.cc(1098)] handshake failed

Python爬虫报错 ERROR:ssl_client_socket_impl.cc(1098)] handshake failed的解决方法

最近在用selenium写爬虫,使用的浏览器是Chrome浏览器,当访问浏览器时出现了以下报错信息:
在这里插入图片描述
解决方案:
浏览器要求您接受网站的证书。您可以设置默认情况下忽略这些错误,以免发生这些错误。

1、对于Chrome,您需要添加 -ignore-certificate-errors 和-ignore-ssl-errors ChromeOptions()参数:

 options = webdriver.ChromeOptions()
 options.add_argument('-ignore-certificate-errors')
 options.add_argument('-ignore -ssl-errors')
 driver = webdriver.Chrome(chrome_options = options)

2、对于Firefox,您需要将 accept_untrusted_certs 设置为True:

 profile = webdriver.FirefoxProfile()
 profile.accept_untrusted_certs = True 
 driver = webdriver.Firefox(firefox_profile = profile)

3、对于Internet Explorer,您需要设置 acceptSslCerts 所需的功能:

caps = webdriver.DesiredCapabilities.INTERNETEXPLORER
caps['acceptInsecureCerts'] = True
caps['acceptSslCerts'] = True
driver = webdriver.Ie(capabilities = capabilities)
上述代码任然无法正常运行,请你优化。要能正常运行后再发给我。上述代码无法正常运行,终端显示为:PS C:\Users\14743\Desktop\PY> & "D:/py anzhuangbao/python.exe" c:/Users/14743/Desktop/6.7爬虫作业.py DevTools listening on ws://127.0.0.1:49660/devtools/browser/014a93f0-9c97-4a34-91b3-7fa1882fb4bf [16968:23176:0607/092500.308:ERROR:chrome\browser\importer\edge_china_browsers\edge_qqbrowser_importer_utils_win.cc:198] QQBrowser profile preference file doesn't exist [19760:6684:0607/092500.766:ERROR:net\socket\ssl_client_socket_impl.cc:892] handshake failed; returned -1, SSL error code 1, net_error -101 [19760:6684:0607/092500.934:ERROR:net\socket\ssl_client_socket_impl.cc:892] handshake failed; returned -1, SSL error code 1, net_error -101 Traceback (most recent call last): File "c:\Users\14743\Desktop\6.7爬虫作业.py", line 22, in <module> first_category = driver.find_element(By.XPATH, '//*[@id="nav"]/li[1]/a') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\py anzhuangbao\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 914, in find_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\py anzhuangbao\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 447, in execute self.error_handler.check_response(response) File "D:\py anzhuangbao\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="nav"]/li[1]/a"} (Session info: MicrosoftEdge=137.0.3296.62); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception Stacktrace: GetHandleVerifier [0x0x7ff736c33915+25605] (No symbol) [0x0x7ff736b83a20] Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff736eb6f2a+1962506] (No symbol) [0x0x7ff7369986c4] (No symbol) [0x0x7ff73699898b] (No symbol) [0x0x7ff7369d9af7] (No symbol) [0x0x7ff7369b9e8f] (No symbol) [0x0x7ff73698ea5d] (No symbol) [0x0x7ff7369d75df] (No symbol) [0x0x7ff7369b9bb3] (No symbol) [0x0x7ff73698df56] (No symbol) [0x0x7ff73698d463] (No symbol) [0x0x7ff73698dd83] (No symbol) [0x0x7ff736a8e10d] (No symbol) [0x0x7ff736a9dce8] Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff736d188e9+265161] Microsoft::Applications::Events::EventProperty::to_string [0x0x7ff736d201c1+296097] (No symbol) [0x0x7ff736b921c1] (No symbol) [0x0x7ff736b8a664] (No symbol) [0x0x7ff736b8a7b3] (No symbol) [0x0x7ff736b7b986] BaseThreadInitThunk [0x0x7ff87f13e8d7+23] RtlUserThreadStart [0x0x7ff88069c5dc+44]
最新发布
06-09
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值