简体   繁体   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

Trying to get selenium to work with Python 3 for web scraping purposes:试图让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)

I get the following error message:我收到以下错误消息:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件

A similar question was addressed here , but what is baffling to me is that Chrome is already installed on my system. 此处解决了类似的问题,但让我感到困惑的是我的系统上已经安装了 Chrome。 The other asker apparently didn't have it on their computer.另一个提问者显然没有在他们的电脑上。 I'm running latest version of Mac OS.我正在运行最新版本的 Mac 操作系统。

The issue is that chromedriver also needs to know where chrome is.问题是 chromedriver 还需要知道 chrome 在哪里。 In your case it is at a non-default path.在您的情况下,它位于非默认路径。 So you need to specify the complete path to the Google Chrome binary.因此,您需要指定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)

Above code is what you should use上面的代码是你应该使用的

I have met this annoying problem when I am lerning selenium.我在学习硒时遇到了这个烦人的问题。 This is my solution: (MacOS 10.13.4)这是我的解决方案:(MacOS 10.13.4)

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

Thanks to homebrew now chrome and chromedriver are installed in the same folder and this problem will be automatically solved.多亏了 homebrew 现在 chrome 和 chromedriver 安装在同一个文件夹中,这个问题会自动解决。

It is important on Win to set the name of chrome.exe otherwise it fail to create a process (see below):在 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: Message: unknown error: Failed to create a Chrome process. selenium.common.exceptions.WebDriverException:消息:未知错误:无法创建 Chrome 进程。

For Firefox (download driver https://github.com/mozilla/geckodriver/releases ):对于 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)

If anyone is getting the same error on a linux machine, then you are missing google chrome installation as one of the steps needed for chrome driver to work.如果有人在 linux 机器上遇到相同的错误,那么您缺少google chrome安装作为 chrome 驱动程序工作所需的步骤之一。

Follow this link to install Google chrome on Linux.按照此链接在 Linux 上安装 Google chrome。

Now, check code现在,检查代码

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])

For me it worked.对我来说它奏效了。

If your chromedriver is located within /Library/Frameworks/Python.framework/Versions/3.6/bin/ directory the following code block should be working for you:如果您的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 浏览器,然后它不会抛出错误。

This article gives the full breakdown on what is happening. 本文详细介绍了正在发生的事情。 Installing the latest web driver should fix the problem rather than changing the code.安装最新的 Web 驱动程序应该可以解决问题,而不是更改代码。

Basically version 85 of chrome was installed in a different location, however this only affected new installations so it wasn't noticeable for most people.基本上 85 版的 chrome 安装在不同的位置,但这仅影响新安装,因此对大多数人来说并不明显。

The latest web driver understands about the new location so getting an updated driver is the easiest solution - that is of course unless you specifically need to test an older version.最新的 Web 驱动程序了解新位置,因此获取更新的驱动程序是最简单的解决方案 - 当然,除非您特别需要测试旧版本。

Location of drivers.司机的位置。

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

I recently solved this issue by simply downloading the Chrome Browser .我最近通过简单地下载Chrome 浏览器解决了这个问题。 Download it and to download latest version of chrome driver by using this code下载它并使用此代码下载最新版本的 chrome 驱动程序

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

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

For mac: Note space between Chrome and .app对于 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: Message: unknown error: no chrome binary selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 OperaDriver Selenium 和 Python 找到 Opera 二进制文件 - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件 - raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用镓和Docker杀死Chrome错误 - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot kill Chrome error with gallium and Docker selenium.common.exceptions.WebDriverException:消息:未知错误:无法在 localhost:8733 \\\\ 连接到 chrome 怎么回事? - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at localhost:8733 \\\\ What's going on? selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process error with ChromeDriver Chrome Selenium selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法以Selenium和RaspberryPi上的Chrome启动 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start with Selenium and Chrome on RaspberryPi selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:使用ChromeDriver Chrome和Selenium异常退出 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用带有Selenium Python的ChromeDriver Chrome创建Chrome进程 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM