selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH

张三的《Python程序开发》课程

selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH. 报错的解决办法

根据错误提示:Message: ‘chromedriver’ executable needs to be in PATH
错误原因:chromedriver需要放在python安装路径下。
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第1张图片

解决办法:
1、下载chromedriver.exe安装包
打开以下chromedriver下载地址:
(1)官网链接,可能部分人打不开http://chromedriver.storage.googleapis.com/index.html
点击Downloads
(2)第一个链接打不开的情况下,请打开这个第三方链接http://npm.taobao.org/mirrors/chromedriver/

两个地址都可以下载,根据自己的chrome浏览器的版本选择下载即可

查看谷歌浏览器版本的办法 ↓
方法1:打开谷歌浏览器,在其地址栏输入 chrome://version 然后回车即可。
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第2张图片
方法2:窗口手动查找法
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第3张图片
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第4张图片
打开,chromedriver下载地址,根据你的版本点击下载。
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第5张图片
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第6张图片
下载解压后
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第7张图片
2、把解压后的chromedriver.exe文件复制到Python安装路径下,如:D:\anaconda3(此步需要根据自己实际安装目录)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第8张图片3、配置环境变量:此电脑→右击属性→高级系统设置→环境变量→用户变量→Path→编辑→新建,将以下chrome浏览器的安装路径复制,然后不要忘记后续全部点击确定。
C:\Users\Administrator\AppData\Local\Google\Chrome\Application
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第9张图片
4、打开pycharm,输入以下代码,测试一下是否驱动成功?

from selenium import webdriver

driver = webdriver.Chrome()
url = ‘https://www.csdn.net/’
driver.get(url)
driver.maximize_window()
下图为驱动测试成功情况下的示意图:
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH_第10张图片

你可能感兴趣的:(python网络爬虫,python,爬虫)