Selenium在Mac上提供"selenium.common.exceptions.WebDriverException:消息:未知错误:无法找到Chrome二进制文件"

Ale*_*ebs 9 selenium python-3.x

尝试selenium使用Python 3进行Web抓取:

from selenium import webdriver
chrome_path = r"/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver"
driver = webdriver.Chrome(chrome_path)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件

这里也解决类似的问题,但令我困惑的是Chrome已经安装在我的系统上.另一个提问者显然没有在他们的电脑上.我正在运行最新版本的Mac OS.

Tar*_*ani 14

问题是chromedriver还需要知道铬的位置.在您的情况下,它处于非默认路径.因此,您需要指定Google Chrome二进制文件的完整路径.

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/usr/local/bin/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
Run Code Online (Sandbox Code Playgroud)

以上代码是你应该使用的


Ash*_*til 7

如果有人在 Linux 计算机上遇到相同的错误,那么您缺少google chrome安装,这是 chrome 驱动程序正常工作所需的步骤之一。

点击此链接在 Linux 上安装 Google chrome。

现在,检查代码

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
Run Code Online (Sandbox Code Playgroud)

对我来说它有效。


Max*_*ner 7

在 Win 上设置 chrome.exe 的名称很重要,否则无法创建进程(见下文):

  from selenium import webdriver
  from webdriver_manager.chrome import ChromeDriverManager

  options = webdriver.ChromeOptions()
  options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
  chrome_driver_binary = r"C:/Users/Max/.wdm/chromedriver/75.0.3770.8/win32/chromedriver.exe"
  driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
  driver.get('http://web.whatsapp.com')
Run Code Online (Sandbox Code Playgroud)

selenium.common.exceptions.WebDriverException:消息:未知错误:无法创建 Chrome 进程。

对于 Firefox(下载驱动程序https://github.com/mozilla/geckodriver/releases):

  options = webdriver.FirefoxOptions()
  #options.add_argument('-headless')
  #options.binary_location = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\geckodriver.exe"
  options.binary_location = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
  firefox_driver_binary = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\\"
  driver = webdriver.Firefox(firefox_driver_binary, options=options)
Run Code Online (Sandbox Code Playgroud)


小智 6

我在学习硒时遇到了这个烦人的问题。这是我的解决方案:(MacOS 10.13.4)

  1. 卸载我的 chrome
  2. 使用自制软件安装 chromedriver: brew cask install chromedriver
  3. 使用自制软件安装 chrome: brew cask install google-chrome

多亏了 homebrew 现在 chrome 和 chromedriver 安装在同一个文件夹中,这个问题会自动解决。

  • 2021 年,只需“brew install google-chrome”即可。 (5认同)