使用undetected_chromedriver遇版本不兼容错误,求解决方案
解决undetected_chromedriver与Chrome版本不兼容问题
问题分析
你遇到的错误是因为undetected_chromedriver加载了版本114的ChromeDriver,但本地Chrome浏览器为103.0.5060.53,两者版本不匹配导致冲突。
解决方案
1. 清理ChromeDriver缓存
undetected_chromedriver会自动下载并缓存ChromeDriver,可能旧的114版本缓存未被替换。手动删除缓存目录:
- Windows:删除
%LOCALAPPDATA%\undetected_chromedriver下所有文件 - Linux/macOS:删除
~/.undetected_chromedriver下所有文件
删除后重新运行代码,库会自动下载对应Chrome 103的ChromeDriver。
2. 手动指定ChromeDriver路径
如果自动下载仍异常,可手动下载与Chrome 103.0.5060.53完全匹配的ChromeDriver,再在代码中指定路径:
import undetected_chromedriver as uc from selenium.webdriver.chrome.service import Service options = uc.ChromeOptions() options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') # 替换为你下载的ChromeDriver实际路径 service = Service(executable_path='/your/path/to/chromedriver_103.0.5060.53') driver = uc.Chrome(options=options, service=service, patcher_force_close=True) driver.get('https://nowsecure.nl') driver.quit()
3. 降级undetected_chromedriver版本
较新版本的undetected_chromedriver可能不再主动支持Chrome 103这类旧版本,可降级到适配版本:
执行命令:
pip install undetected-chromedriver==3.5.3
内容的提问来源于stack exchange,提问作者chens11111010001
相关产品推荐
相关产品推荐

