ubuntu 16.04 安装 python selenium

转:http://blog.csdn.net/heybob/article/details/52922645

1,安装(好像是这样安装的)

$ sudo pip install selenium

 

查看版本

 

>>> import selenium

>>> print selenium.__version__

3.0.1

 

 

2,测试

 

[python] view plain copy

在CODE上查看代码片派生到我的代码片

 

    from selenium import webdriver  

      

    driver = webdriver.Chrome()  

    # driver = webdriver.Firefox()  

    driver.get('http://www.baidu.com')  

    print driver.title  

    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 chrome sudo apt-get install chromium-browser

get appropriate version of chrome driver from here

Unzip the chromedriver.zip

Move the file to /usr/bin directory sudo mv chromedriver /usr/bin

Goto /usr/bin directory and you would need to run something like chmod a+x chromedriver to 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基本安装成功了。

转载于:https://www.cnblogs.com/hizf/p/7772359.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值