簡體   English   中英

Selenium.common.exceptions.WebDriverException:消息:未知錯誤:沒有 chrome 二進制文件

[英]Selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary

我正在嘗試運行幾個月前制作的 python 腳本,該腳本使用 selenium 來抓取 web 頁面。 這是我的代碼:

import pandas as pd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path="/users/aliallam/Documents/chromedriver")

這是我得到的完整錯誤:

Traceback (most recent call last):
  File "/Users/aliallam/Desktop/MISOS_Python_Scraper/main.py", line 16, in <module>
    driver = webdriver.Chrome(executable_path="/users/aliallam/Documents/chromedriver")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

我在這個問題下嘗試了解決方案,但仍然沒有運氣: Selenium 在 Mac 上給出“selenium.common.exceptions.WebDriverException:消息:未知錯誤:找不到 Chrome 二進制文件”

這是我將代碼更改為:

options = webdriver.ChromeOptions()
options.binary_location = " /Applications/Google\ Chrome\ 2.app"
chrome_driver_binary = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary,chrome_options=options)

這真是令人沮喪,一些幫助將不勝感激! 提前致謝!

編輯:除了以下錯誤,我認為您還需要將二進制位置更改為/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome

根據您發布的內容,我認為該錯誤是因為此行中第一個引號后有一個額外的空格:

options.binary_location = " /Applications/Google\ Chrome\ 2.app"

嘗試將其更改為:

options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"

並重新運行代碼。

基於您提供的完整代碼:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary,chrome_options=options)

如果這不起作用,您也可以嘗試

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"
executable_path = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=options)

對於 MacOS 上的我來說,當我將下載的“Google Chrome”應用程序從“下載”文件夾移動到“應用程序”文件夾時,錯誤得到了解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 Selenium 在 Mac 上給出“selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary” raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException:消息:未知錯誤:找不到 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:消息:未知錯誤:無法使用 OperaDriver Selenium 和 Python 找到 Opera 二進制文件 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 Python 中使用 ChromeDriver 和 Selenium 崩潰 selenium.common.exceptions.WebDriverException:消息:未知錯誤:無法使用鎵和Docker殺死Chrome錯誤 selenium.common.exceptions.WebDriverException:消息:未知錯誤:無法在 localhost:8733 \\\\ 連接到 chrome 怎么回事?
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM