|
发表于 2025-4-27 12:17:54
|
显示全部楼层
针对Selenium版本自动检查问题的解决方案
这个问题的根源是Selenium 4.11+版本会强制检查Driver版本信息。以下是两种实测有效的方法:
- 方法一:升级到最新版Selenium并禁用检查
升级到Selenium 4.16+后,可以通过Service参数禁用版本检查:
- from selenium import webdriver
- from selenium.webdriver.chrome.service import Service
- service = Service(disable_version_check=True) # 关键参数
- driver = webdriver.Chrome(service=service)
复制代码
- 方法二:修改Chrome启动参数(通用方案)
通过实验性选项禁用自动化控制扩展:
- options = webdriver.ChromeOptions()
- options.add_experimental_option("excludeSwitches", ["enable-automation"])
- options.add_experimental_option("useAutomationExtension", False)
- # 如果仍报错可追加
- options.add_argument("--disable-blink-features=AutomationControlled")
- options.add_argument("--disable-build-check")
- driver = webdriver.Chrome(options=options)
复制代码
验证要点:
如果仍存在问题,可以尝试在hosts文件中屏蔽相关域名(需要管理员权限):
- 127.0.0.1 googlechromelabs.github.io
- ::1 googlechromelabs.github.io
复制代码
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|