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

Python+Selenium爬取时遇Chrome binary找不到问题求助

解决"unknown error: cannot find Chrome binary"报错

原因及对应解决方案

1. 手动指定Chrome二进制文件路径

如果Chrome未安装在系统默认路径,webdriver无法自动识别位置,需在代码中明确指定:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

try:
    options = Options()
    # 根据你的系统替换路径:
    # Windows示例:options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
    # macOS示例:options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    # Linux示例:options.binary_location = "/usr/bin/google-chrome"
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
except Exception as e:
    print("An error occurred:", str(e))

提示:打开Chrome后输入chrome://version/,复制"可执行文件路径"的值即可得到准确路径

2. 清理ChromeDriver缓存

ChromeDriverManager可能缓存了旧版本驱动,导致匹配异常。手动删除缓存后重新运行代码:

  • Windows缓存路径:C:\Users\<你的用户名>\.wdm\drivers\chromedriver
  • macOS/Linux缓存路径:~/.wdm/drivers/chromedriver
    删除对应版本的文件夹后,重新执行代码。

3. 重置Chrome安装

若上述方法无效,卸载当前Chrome,重新下载官方版本并安装到系统默认路径,再测试代码。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:14:50