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

Selenium运行出现证书解析错误,寻求解决办法

问题描述

以下是用于提取网站数据的Python代码:

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import numpy as np
from csv import writer
from selenium.webdriver.chrome.options import Options
import time


options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])

# Initialize the webdriver
Path= r"C:\Users\xxx\Downloads\Python\chromedriver.exe"

#Configuration
driver  = webdriver.Chrome(Path)

# Navigate to the website containing the HTML code
driver.get("https://app.mohiguide.com/search/result?type=3&parent=6")

# Find the element with the data-src attribute using class name
element = driver.find_element(By.CLASS_NAME, 'title')

# Extract the value of the data-src attribute
data_src = element.get_attribute("data-src")

# Print the value of data-src
print(data_src)

# Close the webdriver
driver.quit()

运行代码时出现证书解析错误:

[4192:22976:0722/130914.625:ERROR:cert_issuer_source_aia.cc(34)] Error parsing cert retrieved from AIA (as DER):
ERROR: Couldn't read tbsCertificate as SEQUENCE
ERROR: Failed parsing Certificate

该代码一年前可正常运行,现需解决此问题。

解决方法
  • 匹配ChromeDriver与Chrome版本:Selenium对浏览器和驱动版本一致性要求高,版本不匹配会引发证书处理逻辑冲突。下载与当前Chrome浏览器版本完全一致的ChromeDriver,替换旧驱动文件。
  • 添加证书忽略参数:在ChromeOptions中加入以下参数,跳过证书验证环节:
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    # 新增证书相关参数
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--ignore-ssl-errors')
    
  • 更新系统根证书:系统根证书过期或缺失会导致网站证书无法解析,手动更新系统根证书列表;也可先在Chrome浏览器中访问目标网站,若提示证书问题,手动信任后再运行代码。
  • 尝试无头模式:无头模式的证书处理逻辑可能不同,添加参数启用:
    options.add_argument('--headless=new')
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 19:48:37