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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM