簡體   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