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

未安装Chrome浏览器时运行Selenium+ChromeDriver的问题求助

问题原因与解决办法

核心问题

你遇到的两种方法失败,本质都是未安装Chrome浏览器:

  • 方法一报错cannot find Chrome binary:ChromeDriver只是驱动程序,必须依赖Chrome浏览器本体才能运行。你尝试把chromedriver.exe路径赋值给binary_location是错误的,这个参数需要指向Chrome浏览器的chrome.exe,但系统中没有该文件,所以报错。
  • 方法二报错AttributeError: 'NoneType' object has no attribute 'split':webdriver_manager会先检测本地Chrome的版本号,再匹配对应版本的ChromeDriver。因为没有安装Chrome,检测结果为None,执行版本切割的split方法时触发错误。

解决办法

方案1:安装Chrome浏览器

这是最直接的解决方案,安装完成后两种方法均可正常使用:

  • 方法一修正:确保ChromeDriver版本与Chrome版本一致,将option.binary_location设置为Chrome的安装路径(例如C:\Program Files\Google\Chrome\Application\chrome.exe)
  • 方法二:无需额外配置,webdriver_manager会自动检测Chrome版本并安装匹配的ChromeDriver

方案2:使用Chrome Headless Shell(无Chrome环境推荐)

如果无法安装Chrome,可以下载与ChromeDriver版本匹配的Chrome Headless Shell(仅包含无头运行的核心组件):

from selenium import webdriver

chromedriver_bin = './materials/chromedriver/chromedriver.exe'
# 替换为你下载的chrome-headless-shell.exe路径
headless_shell_bin = './materials/chrome-headless-shell.exe'

option = webdriver.ChromeOptions()
option.add_argument('--headless')
option.binary_location = headless_shell_bin

service = webdriver.ChromeService(executable_path=chromedriver_bin)

driver = webdriver.Chrome(service=service, options=option)
driver.get('https://www.google.com/')

方案3:改用其他无头浏览器

比如使用EdgeDriver(Windows系统通常自带Edge浏览器):

from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager

option = webdriver.EdgeOptions()
option.add_argument('--headless')

service = webdriver.EdgeService(executable_path=EdgeChromiumDriverManager().install())

driver = webdriver.Edge(service=service, options=option)
driver.get('https://www.google.com/')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 00:22:46