Undetected ChromeDriver版本匹配仍报错,运行成功率50%求助
解决思路
- 排查多版本Chrome残留:系统中可能存在旧版Chrome(如130),导致
undetected_chromedriver随机调用到不匹配版本。手动指定Chrome可执行文件路径,强制使用131版本:
import undetected_chromedriver as uc from selenium.webdriver.chrome.options import Options options = Options() # 替换为你的Chrome实际安装路径,Mac/Linux路径需对应调整 options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe" driver = uc.Chrome(options=options)
- 强制指定ChromeDriver路径:避免库自动下载或调用不匹配的驱动版本,直接指定本地131版本的ChromeDriver路径:
import undetected_chromedriver as uc # 替换为你的ChromeDriver实际路径 driver = uc.Chrome(driver_executable_path="path/to/your/chromedriver.exe")
- 清理Chrome临时数据与进程:残留的会话或后台进程可能干扰版本检测。运行脚本前关闭所有Chrome窗口,结束
chrome.exe、chromedriver.exe相关进程;也可指定全新临时用户目录启动:
import undetected_chromedriver as uc from selenium.webdriver.chrome.options import Options options = Options() # 创建临时目录避免旧数据干扰 options.add_argument("--user-data-dir=C:/temp/chrome_temp_profile") driver = uc.Chrome(options=options)
- 更新
undetected_chromedriver:旧版本库可能存在版本检测逻辑bug,执行命令更新到最新版:
pip install --upgrade undetected-chromedriver
内容的提问来源于stack exchange,提问作者The Oracle
相关产品推荐
相关产品推荐

