鱼C论坛

 找回密码
 立即注册
查看: 1392|回复: 10

Selenium 很烦人的一个 Bug

[复制链接]
发表于 2025-4-27 12:17:54 | 显示全部楼层
针对Selenium版本自动检查问题的解决方案

这个问题的根源是Selenium 4.11+版本会强制检查Driver版本信息。以下是两种实测有效的方法:

  • 方法一:升级到最新版Selenium并禁用检查
    升级到Selenium 4.16+后,可以通过Service参数禁用版本检查:

    1. from selenium import webdriver
    2. from selenium.webdriver.chrome.service import Service

    3. service = Service(disable_version_check=True)  # 关键参数
    4. driver = webdriver.Chrome(service=service)
    复制代码

  • 方法二:修改Chrome启动参数(通用方案)
    通过实验性选项禁用自动化控制扩展:

    1. options = webdriver.ChromeOptions()
    2. options.add_experimental_option("excludeSwitches", ["enable-automation"])
    3. options.add_experimental_option("useAutomationExtension", False)

    4. # 如果仍报错可追加
    5. options.add_argument("--disable-blink-features=AutomationControlled")
    6. options.add_argument("--disable-build-check")

    7. driver = webdriver.Chrome(options=options)
    复制代码



验证要点:


如果仍存在问题,可以尝试在hosts文件中屏蔽相关域名(需要管理员权限):

  1. 127.0.0.1 googlechromelabs.github.io
  2. ::1 googlechromelabs.github.io
复制代码


以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-25 07:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表