尝试让 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: Message: unknown error: cannot find Chrome binary
解决了类似的问题here ,但令我困惑的是 Chrome 已经安装在我的系统上。另一个提问者的计算机上显然没有该信息。我正在运行最新版本的 Mac 操作系统。
最佳答案
问题是 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)
上面的代码是您应该使用的
关于python - Selenium 在 Mac 上给出 "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46026987/