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

问题描述

问题是chromedriver还需要知道chrome在哪里。在您的情况下,它位于非认路径。因此,您需要指定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)

上面的代码是你应该使用的

解决方法

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

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二进制文件

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