ubuntu14.04学习selenium之一:安装

ubuntu14.04学习selenium之一:安装

2016-10-25 15:275028人阅读评论(0)收藏举报

分类:

爬虫(2)软件插件学习(47)

版权声明:本文为博主原创文章,未经博主允许不得转载。

环境:ubuntu14.04,python2.7

1,安装(好像是这样安装的)
$ sudo pip install selenium

查看版本

>>> import selenium
>>> print selenium.__version__
3.0.1

2,测试

[python]view plaincopy

  1. fromseleniumimportwebdriver
  2. driver=webdriver.Chrome()
  3. #driver=webdriver.Firefox()
  4. driver.get('http://www.baidu.com')
  5. printdriver.title
  6. driver.quit()

运行时在driver = webdriver.Chrome()处报错:
OSError: [Errno 20] Not a directory

这里使用webdriver.Chrome()或者webdriver.Firefox()都报一样的错

3,安装driver

找到这个方法:

$ sudo apt-get install chromium-chromedriver

然而并没有效果,卸载之

查了半天,找到下载地址:

chromedriver(Chrome浏览器):

http://chromedriver.storage.googleapis.com/index.html

geckodriver(Firefox浏览器)

https://github.com/mozilla/geckodriver/releases

安装的方法:http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium

'''

  • Check you have installed latest version of chrome brwoser->chromium-browser -version
  • If not,install latest version of chromesudo apt-get install chromium-browser
  • get appropriate version of chrome driver fromhere
  • Unzip the chromedriver.zip
  • Move the file to/usr/bindirectorysudo mv chromedriver /usr/bin
  • Goto/usr/bindirectory and you would need to run something likechmod a+x chromedriverto mark it executable.
  • finally you can execute the code.

    '''

    简单的说,就是下载解压后,放到/usr/bin,然后加上执行权限,命令如下:

    $ unzip chromedriver_linux64.zip

    $ sudo mv chromedriver /usr/bin/

    $ sudo chmod +x chromedriver

    另一个geckodriver也是一样

    4,后记

    再次执行测试代码成功,说明selenium基本安装成功了。

    找了半天安装selenium的博客,但是没看到几个ubuntu下关于driver的具体安装的,所以我这里记录下。

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...