【selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ ...】【 [WinError 2] 系统找不到指定的文】

这篇具有很好参考价值的文章主要介绍了【selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ ...】【 [WinError 2] 系统找不到指定的文】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

一、问题描述

二、问题分析

1、异常一:

2、异常二:

3、分析

三、解决方法

1、geckodriver的下载

2、检查代码

四、验证


filenotfounderror: [winerror 2] 系统找不到指定的文件。,Python,selenium,测试工具,经验分享,pycharm,爬虫

前言

        Selenium的脚本可以控制浏览器进行操作,可以实现多个浏览器的调用,包括 IE (7 8 9 10 11 )、 Firefox Safari Google Chrome Opera 等。常用的是 Firefox ,因此下面的讲解也以 Firefox 为例
        大家对应自己的情况进行去解决。

一、问题描述

        运行代码时程序报错,出现了以下两个异常,即无法使用Selenium打开浏览器和一个网页

F:\PyCharm-community\2020.3.5版本\2020.3\WebScraping\Scripts\python.exe F:/PyCharm-community/pythonProject/WebScraping/11.1.1.py 
Traceback (most recent call last):
  File "F:\PyCharm-community\2020.3.5版本\2020.3\WebScraping\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\MAIBENBEN\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\MAIBENBEN\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\PyCharm-community\pythonProject\WebScraping\11.1.1.py", line 6, in <module>
    driver=webdriver.Firefox()
  File "F:\PyCharm-community\2020.3.5版本\2020.3\WebScraping\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 172, in __init__
    self.service.start()
  File "F:\PyCharm-community\2020.3.5版本\2020.3\WebScraping\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 


Process finished with exit code 1

 文章来源地址https://www.toymoban.com/news/detail-610513.html

 

二、问题分析

1、异常一:

filenotfounderror: [winerror 2] 系统找不到指定的文件。,Python,selenium,测试工具,经验分享,pycharm,爬虫

翻译:

【in_execute_child
hp,ht,pid,tid=_winapi.CreateProcess(可执行文件,参数,
FileNotFoundError:[WinError 2]系统找不到指定的文件。】

2、异常二:

filenotfounderror: [winerror 2] 系统找不到指定的文件。,Python,selenium,测试工具,经验分享,pycharm,爬虫

翻译:

【启动中
引发WebDriverException(
selenium.common.exeptions.WebDriverException:消息:“geckodriver”可执行文件需要在PATH中。】

3、分析

        两个异常都出现了“executable”,而executable的翻译是可执行文件。经过分析可得,是geckodriver.exe的问题。

        首先你的电脑里应该得下载了驱动程序geckodriver.exe;其次看代码中有没有写明geckodriver.exe的地址,如果有,则可能是你地址没有写完整,比如缺了“geckodriver.exe”之类的;如果没有,则加上可执行文件(geckodriver.exe)的地址就可以了。

 

 

三、解决方法

1、geckodriver的下载

链接】:https://github.com/mozilla/geckodriver/releases

        下载相应操作系统的geckodriver,这是一个压缩文件,解压后可以放在桌面,如:C:\Users\santostang\Desktop\geckodriver.exe

2、检查代码

我的geckodriver.exe的地址

                F:\1Senior4\geckodriver---selenium\geckodriver.exe

我的部分代码

filenotfounderror: [winerror 2] 系统找不到指定的文件。,Python,selenium,测试工具,经验分享,pycharm,爬虫

         可见,没有写geckodriver.exe的地址。需要在第6行代码里添加上。

措施

        将

driver = webdriver.Firefox()

        修改为

driver=webdriver.Firefox(executable_path = r'F:\1Senior4\geckodriver---selenium\geckodriver.exe')

 

 

四、验证

        运行代码,成功打开了Firefox浏览器和一个网页

filenotfounderror: [winerror 2] 系统找不到指定的文件。,Python,selenium,测试工具,经验分享,pycharm,爬虫

 

本文至此完,感谢阅读

 

 

到了这里,关于【selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ ...】【 [WinError 2] 系统找不到指定的文】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包