Selenium Firefox webdriver无法抓取证书不合格的HTTPS网站解决办法

最近在使用Selenium Firefox webdriver抓取网页内容,在抓取一些证书不合格的HTTPS网站时,Firefox经常报错,并提示“Your connection is not secure…”的错误提示,返回的错误码为NS_ERROR_NET_INADEQUATE_SECURITY。其中使用的版本如下:

Selenium: 3.14
Python: 3.6
Firefox: 60.6.1

几乎百度、Google了所有的资料,发现通过设置变量accept_insecure_certs、accept_untrusted_certs 的解决方案根本不生效。

options = webdriver.FirefoxOptions()
options.accept_insecure_certs = True

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
profile.assume_untrusted_cert_issuer = False

browser = webdriver.Firefox(firefox_options=options, firefox_profile=profile)
....

最后在stackoverflow.com看到了有人通过创建Firefox配置文件最终解决的办法,最后尝试成功了,特意记录一下解决方法。

一、创建Firefox配置文件

Firefox提示错误信息“Your connection is not secure…”(返回的错误码为NS_ERROR_NET_INADEQUATE_SECURITY),是因默认开启http2导致的,需要禁用http2。方法如下:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值