简体   繁体   English

Selenium.common.exceptions.WebDriverException:消息:未知错误:没有 chrome 二进制文件

[英]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.我正在尝试运行几个月前制作的 python 脚本,该脚本使用 selenium 来抓取 web 页面。 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我在这个问题下尝试了解决方案,但仍然没有运气: Selenium 在 Mac 上给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件”

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编辑:除了以下错误,我认为您还需要将二进制位置更改为/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对于 MacOS 上的我来说,当我将下载的“Google Chrome”应用程序从“下载”文件夹移动到“应用程序”文件夹时,错误得到了解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 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 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:消息:未知错误:无法使用 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:消息:未知错误:无法使用 OperaDriver Selenium 和 Python 找到 Opera 二进制文件 - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary with OperaDriver Selenium and 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 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?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM