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. 使用scrapy-redis搭建分布式爬虫环境

    scrapy-redis简介 scrapy-redis是scrapy框架基于redis数据库的组件,用于scrapy项目的分布式开发和部署. 有如下特征:  分布式爬取 您可以启动多个spider工 ...

  2. pyspark报错Exception: Java gateway process exited before sending its port number解决方法

    1.问题 搭建spark的python环境好后简单使用,源代码如下: 然后就给我丢了一堆错误: 2.解决办法 这里指定一下Java的环境就可以了,添加代码: import os os.environ[ ...

  3. 盒模型 | CSS权重 | CSS层叠

    span{ color:red;} *{ font-family:"楷体";line-height:2em; font-size:18px;} 盒模型 CSS定义所有的元素都可能拥 ...

  4. CCNA 之 六 路由协议 二 EIGRP

    EIGRP(Enhanced IGRP) 增强型内部网关路由协议 注意:这是cisco私有协议:也就是说,该协议只能运行在思科的设备上,如果有其他的厂家的设备,则不能保证能运行此协议: EIGRP的特 ...

  5. .NET Core Blazor 1-Blazor项目文件分析

    .NET Core Blazor 1-Blazor项目文件分析 本节内容为Blazor的基本文件 简介 Blazor是一个使用.NET技术用于代替JavaScript/typescript的前端WEB ...

  6. redis与memcached区别

    不同点: (1) redis中并不是所有数据在有效期内只能常驻内存的(如果需要,可定期同步持久化到磁盘),这是和memcached相比一个最大的区别(memcached中的数据在有效期内是以键值对的形 ...

  7. JQuery动态添加控件并取值

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. IOS开发中制作属于自己的静态库.a、资源库.bundle、.framework

    一.什么是库        库实际上是一种代码共享的方式,主要用于代码重用和源码隐藏,通常分为动态库和静态库. 静态库:链接时完整的拷贝至可执行文件中,被多次使用就有多份冗余拷贝. 动态库:链接时不复 ...

  9. [TimLinux] 理解selinux

    1. 概念 SELinux有三种工作模式:Enforcing, Permissive, disabled.Enforcing对应又有几种修饰(targeted, minimum, mls). 2. 解 ...

  10. hdu2199,double二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199 题意:给一个Y,求满足8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的 ...