[英]Selenium.common.exceptions.WebDriverException: Message: unknown error: no 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)
brew cask install chromedriver
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 瀏覽器,然后它不會拋出錯誤。
您只需要下載最新版本的 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.