ubuntu系統下selenium打開火狐瀏覽器提示'geckodriver' executable needs to be in PATH.解決方法


如果你的selenium是3.X版本的,火狐瀏覽器需要geckodriver這個組件的支持,2.X版本則不需要。

使用selenium自動打開火狐瀏覽器錯誤提示:

Traceback (most recent call last):
  File "/home/yanner/seleniumtest/sousuo.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

ubuntu系統,使用selenium3.X版本的,火狐瀏覽器需要下載geckodriver:

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

下載后直接解壓,將解壓后的文件geckodriver放入/usr/local/bin目錄下(該目錄是存放執行文件的)

打開終端輸入以下命令:

su root (如出現su認證失敗請點擊看上一篇文章)

然后進入文件geckodriver存放的目錄,將該文件復制到/usr/local/bin目錄下

root@yanner-VirtualBox:/home/yanner# cd ruanjian
root@yanner-VirtualBox:/home/yanner/ruanjian# cp geckodriver /usr/local/bin/
root@yanner-VirtualBox:/home/yanner/ruanjian#
再次運行:

from selenium import webdriver
browser = webdriver.Firefox()

不再提示:'geckodriver' executable needs to be in PATH.

 


免責聲明!

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



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