解决 Message: ‘chromedriver‘ executable needs to be in PATH.

问题描述

在使用selenium进行爬虫操作的时候弹出报错:

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

又是一个难搞的错误 。

如果觉得edge不行,转换浏览器

我本来用的是edge浏览器,我发现有点问题,于是,我先换成了谷歌浏览器。

打开anaconda prompt

输入

jupyter notebook --generate-config

查看文件位置。

在最后面加入:

import webbrowser

webbrowser.register("chrome",None,webbrowser.GenericBrowser(u"C:\\Google\\Chrome\\Application\\chrome.exe"))

c.NotebookApp.browser = 'chrome'

注意是双划线。

版本问题

如果发现你的谷歌浏览器是

 这个版本,你会发现在

chromedriver的下载地址:
http://chromedriver.storage.googleapis.com/index.htmlhttps://links.jianshu.com/go?to=http%3A%2F%2Fchromedriver.storage.googleapis.com%2Findex.html

中没有这个版本的,哭了………

 然后你可以去找个网站找一下历史版本

Google Chrome 64bit Windows版_chrome浏览器,chrome插件,谷歌浏览器下载,谈笑有鸿儒 (chromedownloads.net)

现在下载对应版本:

ChromeDriver Mirror (taobao.org)

 

移动文件

为了方便,chromedriver下载之后解压,然后把chromedriver驱动添加到python安装路径下的scripts文件夹里面,这样chromedriver就添加到了环境变量里面,不需要另外配置环境变量 

同时,

将浏览器环境变量添加到path

打开开始菜单->我的电脑(或计算机)->系统属性->高级系统设置->环境变量,编辑用户变量里的path,将谷歌路径也保存进去

如果还不行

加上这个代码!!!!


from selenium import webdriver
driver = webdriver.Chrome()

 

物联沃分享整理
物联沃-IOTWORD物联网 » 解决 Message: ‘chromedriver‘ executable needs to be in PATH.

发表评论