【问题标题】:Unable to Run Selenium with Firefox (Python)无法使用 Firefox (Python) 运行 Selenium
【发布时间】:2017-05-08 10:53:37
【问题描述】:

更新后我完全无法让 Selenium (3.0.1) 与 Firefox (50.1.0) 一起使用。这是我正在运行的代码,出现相关错误:

from selenium import webdriver

website = 'www.google.com'

driver = webdriver.Firefox() 
driver.get(website)

这会产生以下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver'executable needs to be in PATH.

我已经阅读了很多关于需要将各种可执行文件添加到我的 PATH 变量以运行 Selenium 的帖子,但到目前为止我完全失败了。我当前的 PATH 变量如下:

$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

我无法成功附加 firefox 或 geckodriver 可执行文件。它似乎已经存在(我已将可执行文件复制到“/usr/local/bin”,但它仍然给我同样的错误。非常感谢任何和所有帮助(Mac OS X 用户)

【问题讨论】:

标签: python selenium firefox web-scraping geckodriver


【解决方案1】:

像往常一样,一周没有解决这个问题,然后重新搜索问题,我能够解决它。此链接中给出了帮助我的提示:

Selenium in Python on Mac - Geckodriver executable needs to be in PATH

我没有将 geckodriver.exe 文件添加到正确的路径。当我下载文件并将其移动到我的 anaconda bin 时,它工作得很好:

mv geckodriver /anaconda/bin #导航到我的下载后

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    您也可以在运行时将路径附加到 PATH 变量。

    import sys
    

    sys,path.append('the path where the file is stored')

    【讨论】:

      【解决方案3】:

      您可能必须安装 geckodriver 并将其添加到您的执行路径中。使用以下 bash 命令安装最新的 geckodriver:

      which geckodriver || (wget https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && tar -C /opt -xzf /tmp/geckodriver.tar.gz && chmod 755 /opt/geckodriver && ln -fs /opt/geckodriver /usr/bin/geckodriver && ln -fs /opt/geckodriver /usr/local/bin/geckodriver)
      

      这将为您安装 geckodriver v0.14.0。我用最新的 Firefox 51.0.1 测试了它

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-07
        • 2018-06-27
        • 1970-01-01
        相关资源
        最近更新 更多