简体   繁体   中英

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

I'm trying to run a python script I made a few months ago which uses selenium to scrape a web page. Here's my code:

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")

Here's the full error I'm getting:

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

I tried the solution under this question, but still no luck: Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

Here's what I changed my code to:

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)

This is really frustrating, some help would be much appreciated! Thanks in advance!

EDIT: In addition to the following mistake, I think you also need to change the binary location to be /Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome

Based on what you posted, I think the error is because of an extra space located after the first quotation mark in this line:

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

Try changing that to:

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

and rerunning the code.

Full code based on what you provided:

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)

If that doesn't work, you could also try

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)

For me on MacOS the error got solved when I moved my downloaded "Google Chrome" application from "Downloads" folder to "Applications" Folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process error with ChromeDriver Chrome Selenium selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start with Selenium and Chrome on RaspberryPi selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and Python selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python selenium.common.exceptions.WebDriverException: Message: unknown error: cannot kill Chrome error with gallium and Docker selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at localhost:8733 \\\\ What's going on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM