使用Mac的Python +浏览器:错误 - 'chromedriver'可执行文件需要在PATH中

Jo *_* Ko 9 python browser macos splinter

我做了以下但发现了错误:

selenium.common.exceptions.WebDriverException:消息:'chromedriver'可执行文件需要在PATH中.请参阅 https://sites.google.com/a/chromium.org/chromedriver/home

from splinter import Browser

browser = Browser('chrome')
Run Code Online (Sandbox Code Playgroud)

如何使用Mac解决问题?

提前谢谢,一定会upvote /接受答复!

bre*_*nan 19

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

brew cask install chromedriver
Run Code Online (Sandbox Code Playgroud)

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

编辑:chromedriver从homebrew/core迁移到homebrew/cask

  • 请更新到新语法:brew install --cask chromedriver (2认同)

use*_*273 9

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())

Run Code Online (Sandbox Code Playgroud)

注意:您可能还需要执行以下操作: brew cask install google-chrome

或者

brew install --cask chromedriver

取决于您的 brew 版本。