python编写selenium自动化脚本时报错

志村氏 2019-06-19 11:00:59
本人超级菜鸟一枚 目前自学中 python环境什么的应该都按照教程配置好了 脚本也是照抄的 但还是报错了。。。求大神解答
脚本如下:
# coding=utf-8
from selenium import webdriver

driver=webdriver.Firefox()
driver.get("http://www.baidu.com")

driver.find_element_by_id("kw").send_keys("selenium2")
driver.find_element_by_id("su").click()
driver.quit()

报错内容如下:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/baidu.py", line 4, in <module>
driver=webdriver.Firefox()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
...全文
253 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
洗白白做好猪 2019-07-02
  • 打赏
  • 举报
回复
原声驱动问题。如果不知道驱动放哪里的话建议实例化driver对象的时候指明驱动文件的路径。.
志村氏 2019-06-20
  • 打赏
  • 举报
回复
引用 5 楼 陈年椰子 的回复:
https://blog.csdn.net/jelly441/article/details/81706297
非常感谢!!!
陈年椰子 2019-06-20
  • 打赏
  • 举报
回复
Firefox 装了吗?
志村氏 2019-06-20
  • 打赏
  • 举报
回复
跪求大佬 一直调试不通 不知道是什么情况…
陈年椰子 2019-06-20
  • 打赏
  • 举报
回复
https://blog.csdn.net/jelly441/article/details/81706297
陈年椰子 2019-06-20
  • 打赏
  • 举报
回复
那是 GeckoDriver 没装
参考下这个
https://blog.csdn.net/qq_42543250/article/details/81290876
志村氏 2019-06-20
  • 打赏
  • 举报
回复
引用 2 楼 陈年椰子 的回复:
Firefox 装了吗?
装好了 官网下载的最新版

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧