Mac 爬虫error: chromedriver' executable needs to be in PATH


安装selenium

pip install selenium

Mac 下使用selenium打开一个空的浏览器窗口:

from selenium import webdriver
driver = webdriver.Chrome()

报错:

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

解决

方法一:直接下载chromedriver并添加路径

1.下载chromedriver,查看chrome浏览器版本为62 下载地址:http://npm.taobao.org/mirrors/chromedriver/2.33/

下载成功,无需安装

2.添加chromedriver路径,再次运行:

from selenium import webdriver
driver = webdriver.Chrome('你下载的chromedriver的路径')

打开网页成功,问题解决!

方法二:使用brew安装chromedriver

$ brew install chromedriver

2.安装完成后,再次运行:

from selenium import webdriver
driver = webdriver.Chrome()

打开网页成功,问题解决!

附件: