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系统

  1. 下载geckodriver.exe:

    下载地址:https://github.com/mozilla/geckodriver/releases

    请根据系统版本选择下载;(如Windows 64位系统)

  2. 下载解压后将getckodriver.exe复制到Firefox的安装目录下,如(C:\Program Files\Mozilla Firefox),并在环境变量Path中添加路径:C:\Program Files\Mozilla Firefox;

  3. 重启cmd后,再次运行代码即可

ubuntu系统

  1. 下载 geckodriverckod 地址:https://github.com/mozilla/geckodriver/releases
  2. 解压后将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的安装、报错和解决的更多相关文章

  1. Adobe Flash CC 安装报错的解决办法

    安装FlashCC的时候莫名的报错 ---------------------------Flash.exe - 应用程序错误---------------------------应用程序无法正常启动 ...

  2. XAMPP安装报错及解决

    FROM:http://www.zeeronsolutions.com/installing-xampp-on-windows-7-user-account-control-uac-warning-m ...

  3. TensorFlow 安装报错的解决办法(安装1.5版本)

    1.安装Anaconda 百度下载windows版本,一路点下一步,安装好了Anaconda,自带python3.6.6. 2.安装TensorFlow (1)打开Anaconda Prompt,输入 ...

  4. TensorFlow 安装报错的解决办法

    最近关注了几个python相关的公众号,没事随便翻翻,几天前发现了一个人工智能公开课,闲着没事,点击了报名. 几天都没有音信,我本以为像我这种大龄转行的不会被审核通过,没想到昨天来了审核通过的电话,通 ...

  5. WebEssentials 在vs2013 update5安装报错的解决方法.

    WebEssentials 最高支持到update4 如果更新到了update5 RC, 则无法直接安装. 解决方法是 1,下载WebEssentials2013.vsix 文件. 2, 安装7zip ...

  6. 在Linux下JDK1.4.2安装报错的解决方法

    JDK1.4.2的安装   Do you agree to the above license terms? [yes or no]   yes   Unpacking...   tail: cann ...

  7. photoshopcs5 win7安装报错的解决

    因为之前安装了绿色中文破解版的PhotoShop CS5,虽然卸载了,但是注册表还可能残留了其它信息,导致在安装Adobe PhotoShop CS5英文版时一直显示 (Exit Code: 7 ER ...

  8. webpack——安装报错及解决办法

    ①先删除 删除全局webpack-cli webpack4.x开始官方文档是说要安装cli所以如果的在用4.+就需要卸载cli npm uninstall -g webpack-cli # 注释给我这 ...

  9. window7下安装第三方包报错及解决

    window7 64位下安装第三方包,,比如安装yaml的exe执行文件,会 报错及解决:python version 2.7(3.4) required,which was not found in ...

  10. mac用pecl安装swoole可能出现的报错及解决办法

    一.用pecl安装swoole 2018年4月,由于homebrew的变动,导致无法使用brew install的方式安装php的扩展,现在改为用pecl安装,pecl安装swoole的方法为: pe ...

随机推荐

  1. day 49

    今日内容 标签操作 样式操作 样式类操作 addClass(); // 添加指定的CSS类名. removeClass(); // 移除指定的CSS类名. hasClass(); // 判断样式存不存 ...

  2. echarts对柱状图进行标注,以及取消hover时的阴影

    option = { color: ['#3398DB'], tooltip : { trigger: 'axis', axisPointer : { // 坐标轴指示器,坐标轴触发有效 type : ...

  3. SpringMVC 请求参数绑定

    什么是请求参数绑定 请求参数格式 默认是key/value格式,比如:http:xxxx?id=1&type=2 请求参数值的数据类型 都是字符串类型的各种值 请求参数值要绑定的目标类型 Co ...

  4. spring奇怪异常记录(会逐渐记录)

    1 严重: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error cr ...

  5. 浏览器中的 Event Loop

    当我们执行 JS 代码的时候其实就是往执行栈中放入函数,那么遇到异步代码的时候该怎么办?其实当遇到异步的代码时,会被挂起并在需要执行的时候加入到 Task(有多种 Task) 队列中.一旦执行栈为空, ...

  6. 告别编码5分钟,命名2小时!史上最全的Java命名规范参考!

    简洁清爽的代码风格应该是大多数工程师所期待的.在工作中笔者常常因为起名字而纠结,夸张点可以说是编程5分钟,命名两小时!究竟为什么命名成为了工作中的拦路虎. 每个公司都有不同的标准,目的是为了保持统一, ...

  7. Android 子线程更新UI 异常

    众所周知,Android是不可以在子线程中直接更新UI的,需要借助Handler或者View.post(Runnable runnable)或者runOnUIThread(Runnable runna ...

  8. 《Windows内核安全与驱动开发》 3.2 内存与链表

    <Windows内核安全与驱动开发>阅读笔记 -- 索引目录 <Windows内核安全与驱动开发> 3.2 内存与链表 1. 尝试生成一个链表头并将其初始化. 2. 尝试向内存 ...

  9. 【限时免费】从入门到实战,5节课玩转Kafka!赢音箱、书籍好礼!

    欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...

  10. 索引很难么?带你从头到尾捋一遍MySQL索引结构,不信你学不会!

    前言 Hello我又来了,快年底了,作为一个有抱负的码农,我想给自己攒一个年终总结.自上上篇写了手动搭建Redis集群和MySQL主从同步(非Docker)和上篇写了动手实现MySQL读写分离and故 ...