![](/img/trans.png)
[英]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.