带Mac的Python+浏览器:错误-“chromedriver”可执行文件需要在路径中

2024-05-03 04:11:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了以下操作,但遇到了错误:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

from splinter import Browser

browser = Browser('chrome')

如何使用Mac解决问题?

提前谢谢你,一定要投赞成票/接受回答!


Tags: topathinbrowsermessageselenium错误be
2条回答

brew cask install chromedriver

从brew安装chromedriver的当前工作命令,因为之前接受的答案已经过时了。

然后需要与您的selinium代码配对:

chrome_path = r'/usr/local/bin/chromedriver' #path from 'which chromedriver'
driver = webdriver.Chrome(executable_path=chrome_path)

or 

import os 

driver = webdriver.Chrome(executable_path=os.popen('which chromedriver').read().strip())

注意:您可能还需要: brew cask install google-chrome

解决此问题的最简单方法是在Mac上:

brew cask install chromedriver

Splinter和类似的浏览器自动化框架依赖于在PATH中安装和调用的外部模块。

编辑:chromedriver从自制/核心迁移到自制/木桶

相关问题 更多 >