Selenium给出"selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件"在Mac上 [英] Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

查看:418
本文介绍了Selenium给出"selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件"在Mac上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使selenium与Python 3配合使用以进行网络抓取:

Trying to get selenium to work with Python 3 for web scraping purposes:

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二进制文件

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

解决了类似的问题这里,但令我感到困惑的是我的系统上已经安装了Chrome.另一个提问者显然没有在他们的计算机上安装它.我正在运行最新版本的Mac OS.

A similar question was addressed here, but what is baffling to me is that Chrome is already installed on my system. The other asker apparently didn't have it on their computer. I'm running latest version of Mac OS.

推荐答案

问题是chromedriver还需要知道chrome在哪里.在您的情况下,它位于非默认路径.因此,您需要指定Google Chrome二进制文件的完整路径.

The issue is that chromedriver also needs to know where chrome is. In your case it is at a non-default path. So you need to specify the complete path to the Google Chrome binary.

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)

您应该使用以上代码

这篇关于Selenium给出"selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件"在Mac上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆