Selenium 给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件";在 Mac 上 [英] Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

查看:49
本文介绍了Selenium 给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件";在 Mac 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试让 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)

以上代码是你应该使用的

Above code is what you should use

这篇关于Selenium 给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件";在 Mac 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆