ubuntu 16.04 安裝 python selenium

原文是環境:ubuntu14.04, python2.7

本地環境:ubuntu16.04, python2.7


轉自 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基本安裝成功了。


找了半天安裝selenium的博客,但是沒看到幾個ubuntu下關於driver的具體安裝的,所以我這裏記錄下。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章