[英]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.