You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Selenium 4.10.0 Python绕过Firefox的SSL证书警告?

解决Selenium 4.10.0访问自签名SSL网站的SSL警告问题

你之前尝试的几种方法失效,是因为Selenium 4.x版本中,FirefoxOptions的配置逻辑有调整,旧的accept_untrusted_certs属性已不再生效,而acceptInsecureCerts的正确配置方式需要遵循Selenium 4的新语法。

正确的SSL警告绕过配置

直接通过FirefoxOptions设置acceptInsecureCerts能力,这是当前Selenium 4.x版本适配Firefox的标准写法:

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.set_capability("acceptInsecureCerts", True)

driver = webdriver.Firefox(options=options)
driver.get("https://self-signed.badssl.com/")

如果上述方法仍无法解决问题,将自签名.pem证书添加到浏览器信任列表是更可靠的方案,尤其适合证书配置特殊的网站,具体操作步骤如下:

手动配置信任证书并在Selenium中复用

  • 创建一个Firefox配置文件:在Firefox地址栏输入about:profiles,选择「创建新配置文件」完成创建
  • 导入信任证书:打开该配置文件对应的Firefox实例,通过「设置」-「隐私与安全」-「证书」-「查看证书」导入你的自签名.pem文件,并将其设置为受信任的证书
  • 在Selenium中指定该配置文件:
from selenium import webdriver

options = webdriver.FirefoxOptions()
# 替换为你的Firefox配置文件实际路径
options.add_argument("-profile")
options.add_argument("/Users/xxx/Library/Application Support/Firefox/Profiles/xxxxxx.default-release")

driver = webdriver.Firefox(options=options)
driver.get("你的目标网站URL")

这种方式完全模拟手动信任证书的操作,能彻底消除SSL警告,适合长期运行的自动化任务。

内容的提问来源于stack exchange,提问作者bleulenni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 13:42:39