selenium的安装、报错和解决
selenium是的作用是模拟点击浏览器上的按钮,配合一个无头浏览器就可以快速解决一些前端需要加解密的功能。
第一步pip install
selenium安装的第一步就是用pip把模块下载回来。
pip install selenium
具体报错信息如下:
File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b2-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 65, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b2-py2.7.egg/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f753ad53390>> ignored
# 发现报错信息包含: Message: 'geckodriver' executable needs to be in PATH
报错原因 :
是因为缺少依赖包geckodriver,所以在安装selenium之前,先把geckodriver安装上就能解决了。
不同平台下有不同解决方案:
Windows系统
下载geckodriver.exe:
下载地址:https://github.com/mozilla/geckodriver/releases
请根据系统版本选择下载;(如Windows 64位系统)
下载解压后将getckodriver.exe复制到Firefox的安装目录下,如(C:\Program Files\Mozilla Firefox),并在环境变量Path中添加路径:C:\Program Files\Mozilla Firefox;
重启cmd后,再次运行代码即可
ubuntu系统
- 下载 geckodriverckod 地址:https://github.com/mozilla/geckodriver/releases
- 解压后将geckodriverckod 存放至 /usr/local/bin/ 路径下即可
Mac OS系统:
如果你已经安装好了brew,那么输入如下两条命令即可
brew install geckodriver
brew link geckodriver
Mac OS检验geckodriver是否安装成功,
# shell窗口下输入命令
geckodriver
# 什么都不输出,也不退出,说明安装成功
# 注意:windows 系统需要重启一个新cmd窗口在输命令
最后使用pip list查看一下已安装的库:

发现已经包含selenium,说明安装成功。
第二步Python运行Demo
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')
报错:
Traceback (most recent call last):
File "D:\programfiles\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "D:\programfiles\Anaconda3\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "D:\programfiles\Anaconda3\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/code/commany/python/APPScan/main.py", line 7, in <module>
browser = webdriver.Chrome()
File "D:\programfiles\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "D:\programfiles\Anaconda3\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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
没有安装chromedriver导致的,参考自己chrome浏览版本对应的chromedriver版本:
https://my.oschina.net/u/3367404/blog/3011400
chromedriver下载地址:
https://chromedriver.storage.googleapis.com/index.html
下载完成后,将ChromeDriver的可执行文件配置到环境变量下。
如果使用Windows,建议直接将chromedriver.exe文件拖到Python的Scripts目录下。

再次运行脚本,发现会新弹出一个新chrome。

selenium的安装、报错和解决的更多相关文章
- Adobe Flash CC 安装报错的解决办法
安装FlashCC的时候莫名的报错 ---------------------------Flash.exe - 应用程序错误---------------------------应用程序无法正常启动 ...
- XAMPP安装报错及解决
FROM:http://www.zeeronsolutions.com/installing-xampp-on-windows-7-user-account-control-uac-warning-m ...
- TensorFlow 安装报错的解决办法(安装1.5版本)
1.安装Anaconda 百度下载windows版本,一路点下一步,安装好了Anaconda,自带python3.6.6. 2.安装TensorFlow (1)打开Anaconda Prompt,输入 ...
- TensorFlow 安装报错的解决办法
最近关注了几个python相关的公众号,没事随便翻翻,几天前发现了一个人工智能公开课,闲着没事,点击了报名. 几天都没有音信,我本以为像我这种大龄转行的不会被审核通过,没想到昨天来了审核通过的电话,通 ...
- WebEssentials 在vs2013 update5安装报错的解决方法.
WebEssentials 最高支持到update4 如果更新到了update5 RC, 则无法直接安装. 解决方法是 1,下载WebEssentials2013.vsix 文件. 2, 安装7zip ...
- 在Linux下JDK1.4.2安装报错的解决方法
JDK1.4.2的安装 Do you agree to the above license terms? [yes or no] yes Unpacking... tail: cann ...
- photoshopcs5 win7安装报错的解决
因为之前安装了绿色中文破解版的PhotoShop CS5,虽然卸载了,但是注册表还可能残留了其它信息,导致在安装Adobe PhotoShop CS5英文版时一直显示 (Exit Code: 7 ER ...
- webpack——安装报错及解决办法
①先删除 删除全局webpack-cli webpack4.x开始官方文档是说要安装cli所以如果的在用4.+就需要卸载cli npm uninstall -g webpack-cli # 注释给我这 ...
- window7下安装第三方包报错及解决
window7 64位下安装第三方包,,比如安装yaml的exe执行文件,会 报错及解决:python version 2.7(3.4) required,which was not found in ...
- mac用pecl安装swoole可能出现的报错及解决办法
一.用pecl安装swoole 2018年4月,由于homebrew的变动,导致无法使用brew install的方式安装php的扩展,现在改为用pecl安装,pecl安装swoole的方法为: pe ...
随机推荐
- JDK API1.6常用方法
一.String类 常见用法 : (String类代表字符串,JAVA程序中的所有字符串字面值(如“abc”)都作为此类的实例实现,字符串是常量,他们的值在创建之后不能更改,字符串缓冲区支持可变的字符 ...
- Lambda入门,看这一篇幅就够了
jdk1.8中的lambda表达式学习笔记 一.引入一个例子 我们写一个多线程的例子,如下:采用实现Runable接口的方式 package cn.lyn4ever.lambda; public cl ...
- sortColors
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the ...
- day20191102笔记
当日所学默写笔记: 1.select id="唯一,必须写,对应的接口方法名称" resultType="必须写,返回的类型是对应持久化数据层的全限定类名或者是其别名&q ...
- sudo控制用户对系统命令的使用权限
sudo控制用户对系统命令的使用权限 sudo相关概念 普通用户涉及到超级权限的运用,管理员如果想让该普通用户通过su来切换到root获得超级权限,就必须把root权限密码告诉用户.但是如果普通用户有 ...
- 为NLog自定义LayoutRenderer
长话短说 前文<解剖HttpClientFactory,自由扩展HttpMessageHandler>主要想讲如何扩展HttpMessageHandler, 示例为在每个Http请求中的 ...
- Spring Boot中使用Jpa的findOne方法不能传入id
最近通过慕课网学习spring boot,视频中通过jpa的findOne方法以id为参数查询出对应的信息, 而当我自己做测试的时候却发现我的findOne方法的参数没有Integer类型的id,而是 ...
- Flask使用bootstrap为HttpServer添加上传文件功能
关于模态框 使用bootstrap实现点击按钮弹出窗口,简直不要太简单.我们只需要将写好的窗口内容隐藏,然后调用bootstrap的框架即可,简单几行就能完成相关功能实现.... 前提条件是,我们需要 ...
- 自学python中的心得
以后的日子里我将与可爱的亲们一起度过我自学python的岁月,请博客园里的大佬们监督与见证.
- 定时器注解 @Scheduled 使用
试列代码: @Component @Slf4j //配置文件注入注解 @PropertySource("classpath:/**.properties") public clas ...