Selenium给出"selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件"在Mac上

Selenium给出

问题描述:

尝试使selenium与Python 3配合使用以进行网络抓取:

Trying to get selenium to work with Python 3 for web scraping purposes:

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

我收到以下错误消息:

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

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

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

A similar question was addressed here, but what is baffling to me is that Chrome is already installed on my system. The other asker apparently didn't have it on their computer. I'm running latest version of Mac OS.

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

The issue is that chromedriver also needs to know where chrome is. In your case it is at a non-default path. So you need to specify the complete path to the Google Chrome binary.

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)

您应该使用以上代码