zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    HDU --1251
    POJ -- 2436
    POJ -- 3140
    POJ 3107
    POJ -- 2002
    POJ -- 1655
    lintcode154
    lintcode192
    lintcode582
    lintcode901
  • 原文地址:https://www.cnblogs.com/yanner/p/11077762.html
Copyright © 2011-2022 走看看