Python + 带有 Mac 的浏览器:错误 - 'chromedriver' 可执行文件需要位于 PATH 中
Python + Browser with Mac: Error - 'chromedriver' executable needs to be in PATH
我做了以下但遇到了错误:
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 解决问题?
提前谢谢您,一定会upvote/accept回答!
在 Mac 上解决此问题的最简单方法是:
brew cask install chromedriver
用于浏览器自动化的 Splinter 和类似框架依赖于在 PATH 中安装和调用的外部模块。
编辑:chromedriver 从 homebrew/core 迁移到 homebrew/cask
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
或
brew install --cask chromedriver
取决于您的 brew 版本。
按照这三个步骤,一切就绪!!!
将执行文件的用户的 exe 文件权限更改为 read/write。
检查驱动版本是否与浏览器版本一致
也不要在python路径中给出.exe(只需在路径中提供最多chromedriver
)
示例:
driver = webdriver.Chrome(executable_path="/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/chromedriver")
我做了以下但遇到了错误:
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 解决问题?
提前谢谢您,一定会upvote/accept回答!
在 Mac 上解决此问题的最简单方法是:
brew cask install chromedriver
用于浏览器自动化的 Splinter 和类似框架依赖于在 PATH 中安装和调用的外部模块。
编辑:chromedriver 从 homebrew/core 迁移到 homebrew/cask
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
或
brew install --cask chromedriver
取决于您的 brew 版本。
按照这三个步骤,一切就绪!!!
将执行文件的用户的 exe 文件权限更改为 read/write。
检查驱动版本是否与浏览器版本一致
也不要在python路径中给出.exe(只需在路径中提供最多
chromedriver
)
示例:
driver = webdriver.Chrome(executable_path="/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/chromedriver")