繁体   English   中英

Selenium 在 Mac 上给出“selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary”

[英]Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

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

我收到以下错误消息:

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

此处解决了类似的问题,但让我感到困惑的是我的系统上已经安装了 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)

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

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

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

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

在 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')

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)
options = webdriver.ChromeOptions()
options.binary_location = r"<YOUR_CHROME_PATH>\chrome.exe"
chrome_driver_path = r"<PATH_TO_CHROME_DRIVER>\chromedriver.exe>"

browser = webdriver.Chrome(chrome_driver_path, chrome_options=options)

如果有人在 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'])

对我来说它奏效了。

如果您的chromedriver位于/Library/Frameworks/Python.framework/Versions/3.6/bin/目录中,则以下代码块应该适合您:

from selenium import webdriver

chrome_path = r'/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver'
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get('https://www.google.co.in')

就我而言,我安装了 Chrome 浏览器,然后它不会抛出错误。

本文详细介绍了正在发生的事情。 安装最新的 Web 驱动程序应该可以解决问题,而不是更改代码。

基本上 85 版的 chrome 安装在不同的位置,但这仅影响新安装,因此对大多数人来说并不明显。

最新的 Web 驱动程序了解新位置,因此获取更新的驱动程序是最简单的解决方案 - 当然,除非您特别需要测试旧版本。

司机的位置。

您只需要下载最新版本的 chrome 和 chromedriver 并安装它

我最近通过简单地下载Chrome 浏览器解决了这个问题。 下载它并使用此代码下载最新版本的 chrome 驱动程序

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

对于 mac:请注意Chrome.app之间的空格

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium.common.exceptions.WebDriverException:消息:未知错误:没有 chrome 二进制文件 selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 OperaDriver Selenium 和 Python 找到 Opera 二进制文件 raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件 selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用镓和Docker杀死Chrome错误 selenium.common.exceptions.WebDriverException:消息:未知错误:无法在 localhost:8733 \\\\ 连接到 chrome 怎么回事? selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误 selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法以Selenium和RaspberryPi上的Chrome启动 selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:使用ChromeDriver Chrome和Selenium异常退出 selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用带有Selenium Python的ChromeDriver Chrome创建Chrome进程 selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM