Python中使用Selenium访问网站并截屏时如何解决SSL证书问题?
[10828:3556:0708/001502.875:ERROR:ssl_client_socket_impl.cc(1026)] handshake failed; returned -1, SSL error code 1, net_error -100 [10828:3556:0708/001504.276:ERROR:ssl_client_socket_impl.cc(1026)] handshake failed; returned -1, SSL error code 1, net_error -100 [10828:3556:0708/001510.780:ERROR:ssl_client_socket_impl.cc(1026)] handshake failed; returned -1, SSL error code 1, net_error -100
这样的错误如何解决?
试了下添加 driver 的参数,貌似还是不行。
另外貌似 selenium 找 element 的速度很慢,如何提高呢?
Python中使用Selenium访问网站并截屏时如何解决SSL证书问题?
再求一个 firefox 用 selenium 浏览器的环境配置教程,总是觉得配置的有问题。网络上各式各样的都有,也没见 selenium 出一个版本对应的关系。有点摸不着边。
遇到SSL证书问题,通常是因为网站证书不被Selenium的WebDriver信任。最直接的解决方法是配置WebDriver忽略SSL错误。以下是Chrome和Firefox的示例代码:
Chrome浏览器解决方案:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://your-website.com')
driver.save_screenshot('screenshot.png')
driver.quit()
Firefox浏览器解决方案:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
firefox_options = Options()
firefox_options.accept_insecure_certs = True
driver = webdriver.Firefox(options=firefox_options)
driver.get('https://your-website.com')
driver.save_screenshot('screenshot.png')
driver.quit()
关键点说明:
- Chrome使用
--ignore-certificate-errors和--ignore-ssl-errors参数 - Firefox设置
accept_insecure_certs = True - 这些配置允许浏览器继续访问具有SSL证书问题的网站
注意: 这种方法会降低安全性,仅建议在测试环境中使用。如果需要在生产环境处理SSL证书,应该使用有效的证书或配置正确的证书验证。
简单说就是通过浏览器选项忽略证书错误。
楼主你知道这些产生的日志怎么屏蔽吗
参考了网上的参数,但是还是不能够屏蔽掉。而且以前没有发生过这个问题。

