使用Python的Selenium - Geckodriver可执行文件需要在PATH中

时间:2016-10-23 21:39:14

标签: python selenium firefox selenium-firefoxdriver geckodriver

我是编程的新手,大约2个月前开始使用Python并且正在浏览Sweigart的使用Python自动化无聊的东西文本。我使用IDLE并且已经安装了selenium模块和Firefox浏览器。 每当我尝试运行webdriver函数时,我都会这样:

from selenium import webdriver
browser = webdriver.Firefox()

例外: -

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Traceback (most recent call last):
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Python\Python35\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Python\Python35\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    browser = webdriver.Firefox()
  File "C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
    self.service.start()
  File "C:\Python\Python35\lib\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. 

我想我需要设置geckodriver的路径但不确定如何,所以有人能告诉我我该怎么做?

36 个答案:

答案 0 :(得分:277)

  

selenium.common.exceptions.WebDriverException:消息:'geckodriver'可执行文件需要在PATH中。

First of all you will need to download latest executable geckodriver from here to run latest firefox using selenium

实际上,Selenium客户端绑定会尝试从系统geckodriver中找到PATH可执行文件。您需要将包含可执行文件的目录添加到系统路径。

  • 在Unix系统上,如果您使用的是与bash兼容的shell,则可以执行以下操作将其附加到系统的搜索路径:

    export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
    
  • 在Windows上,您需要更新路径系统变量,以将完整目录路径添加到可执行geckodriver manuallycommand line (don在将可执行geckodriver添加到系统PATH中后,忘记重新启动系统才能生效。原理与Unix相同。

现在,您可以按照以下方式运行代码: -

from selenium import webdriver

browser = webdriver.Firefox()
  

selenium.common.exceptions.WebDriverException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,未提供'moz:firefoxOptions.binary'功能,并且在命令行上未设置二进制标志

异常清楚地表明你已经安装了firefox其他位置,而Selenium试图找到firefox并从默认位置启动但是找不到。你需要提供明确的firefox安装二进制位置来启动firefox,如下所示: -

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)

答案 1 :(得分:107)

这解决了我。

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
driver.get('http://inventwithpython.com')

答案 2 :(得分:101)

这个步骤在ubuntu firefox 50上为我解决了。

  1. 下载geckodriver

  2. 在/ usr / local / bin

  3. 中复制geckodriver

    您无需添加

    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = True
    firefox_capabilities['binary'] = '/usr/bin/firefox'
    browser = webdriver.Firefox(capabilities=firefox_capabilities)
    

答案 3 :(得分:25)

@saurabh的回答解决了这个问题,但没有解释为什么使用Python自动化无聊的东西不包括这些步骤。

这是因为本书基于selenium 2.x而且该系列的Firefox驱动程序不需要gecko驱动程序。当开发硒时,用于驱动浏览器的Gecko界面不可用。

selenium 2.x系列中的latest version为2.53.6(请参阅this answers,以便更轻松地查看版本)。

2.53.6 version page根本没有提到壁虎。但是从版本3.0.2开始,文档explicitly states需要安装gecko驱动程序。

如果在升级之后(或在新系统上安装),你的软件在之前(或在你的旧系统上)运行良好的软件不再起作用并且你很匆忙,那就把你的virtualenv中的selenium版本固定下来

pip install selenium==2.53.6

但当然,开发的长期解决方案是使用最新版本的selenium设置新的virtualenv,安装gecko驱动程序并测试一切是否仍按预期工作。但主要的版本可能会引入您的书中未涵盖的其他API更改,因此您可能希望坚持使用较旧的selenium,直到您有足够的信心可以自行修复selenium2和selenium3 API之间的任何差异。

答案 4 :(得分:15)

在已安装Homebrew的macOS上,您只需运行终端命令

即可
$ brew install geckodriver

因为自制软件已经扩展了PATH,所以不需要修改任何启动脚本。

答案 5 :(得分:13)

为Selenium Python设置geckodriver:

需要使用FirefoxDriver设置geckodriver路径,如下代码所示:

self.driver = webdriver.Firefox(executable_path = 'D:\Selenium_RiponAlWasim\geckodriver-v0.18.0-win64\geckodriver.exe')

为您合适的操作系统下载geckodriver(来自https://github.com/mozilla/geckodriver/releases) - &gt;将其解压缩到您选择的文件夹中 - &gt;如上所述正确设置路径

我在Windows 10中使用Python 3.6.2和Selenium WebDriver 3.4.3。

设置geckodriver的另一种方法:

i)只需将geckodriver.exe粘贴到/ Python / Scripts /下(在我的情况下文件夹是:C:\ Python36 \ Scripts)
ii)现在编写如下简单代码:

self.driver = webdriver.Firefox()

答案 6 :(得分:7)

MAC的步骤:

简单的解决方案是下载GeckoDriver并将其添加到您的系统PATH中。您可以使用以下两种方法之一:

简短方法:

1)下载并解压缩Geckodriver

2)启动驱动程序时提及路径:

driver = webdriver.Firefox(executable_path='/your/path/to/geckodriver')

长方法:

1)下载并解压缩Geckodriver

2)打开.bash_profile。如果您还没有创建它,可以使用以下命令执行此操作:touch ~/.bash_profile。然后使用:open ~/.bash_profile

打开它

3)考虑到下载文件夹中存在GeckoDriver文件,您可以将以下行添加到.bash_profile文件中:

PATH="/Users/<your-name>/Downloads/geckodriver:$PATH"
export PATH

通过这个,你将GeckoDriver的路径附加到你的系统路径。这告诉系统在执行Selenium脚本时GeckoDriver的位置。

4)保存.bash_profile并强制执行。这会立即加载值而无需重新启动。为此,您可以运行以下命令:

source ~/.bash_profile

5)那就是它。你完成了!您现在可以运行Python脚本。

答案 7 :(得分:6)

为此线程的未来读者提供一些额外的输入/说明:

以下内容足以作为Windows 7,Python 3.6,selenium 3.11的解析:

@ dsalaj在早期针对Unix的这个主题中的注释也适用于Windows;修补PATH环境。 Windows级别的变量可以避免重启Windows系统。

(1)下载geckodriver(如前面这个帖子中所述)并将(解压缩的)geckdriver.exe放在X:\ Folder \ of \ your \ choice

(2)Python代码示例:

import os;
os.environ["PATH"] += os.pathsep + r'X:\Folder\of\your\choice';

from selenium import webdriver;
browser = webdriver.Firefox();
browser.get('http://localhost:8000')
assert 'Django' in browser.title

注意: (1)上述代码可能需要大约10秒才能打开指定网址的Firefox浏览器 (2)如果没有服务器已经在指定的url上运行或者服务一个标题包含字符串'Django'的页面,python控制台将显示以下错误:     selenium.common.exceptions.WebDriverException:消息:达到错误页面:about:neterror?e = connectionFailure&amp; u = http%3A // localhost%3A8000 /&amp; c = UTF-8&amp; f = regular&amp; d = Firefox%20can %E2%80%9

答案 8 :(得分:6)

如果您使用的是Anaconda,则只需激活虚拟环境,然后使用以下command安装 geckodriver

    conda install -c conda-forge geckodriver

答案 9 :(得分:6)

最简单的Windows方式!
here下载最新版本的geckodriver。将 geckodriver.exe 文件添加到python目录(或PATH中已有的任何其他目录)。这应该可以解决问题(在Windows 10上测试)

答案 10 :(得分:5)

geckodriver默认未安装。

$ geckodriver

Command 'geckodriver' not found, but it can be installed with:

sudo apt install firefox-geckodriver

$

以下命令不仅会安装它,还将其放在可执行文件PATH中。

sudo apt install firefox-geckodriver

仅需一步即可解决问题。我遇到的错误与您完全相同,安装后它就消失了。继续尝试一下。

$ which geckodriver
/usr/bin/geckodriver
$
$ geckodriver
1337    geckodriver    INFO    Listening on 127.0.0.1:4444
^C

答案 11 :(得分:4)

考虑安装容器化的Firefox:

docker pull selenium/standalone-firefox
docker run --rm -d -p 5555:4444 --shm-size=2g selenium/standalone-firefox

使用webdriver.Remote连接:

driver = webdriver.Remote('http://localhost:5555/wd/hub', DesiredCapabilities.FIREFOX)
driver.set_window_size(1280, 1024)
driver.get('https://toolbox.googleapps.com/apps/browserinfo/')
driver.save_screenshot('info.png')

答案 12 :(得分:3)

我正在使用Windows 10,这对我有用:

  1. documentation下载geckodriver。为您正在使用的计算机下载正确的版本
  2. 解压缩刚刚下载的文件并剪切/复制其中包含的“.exe”文件
  3. 导航到C:{your python root folder}。我的是C:\ Python27。将geckodriver.exe文件粘贴到此文件夹中。
  4. 重新启动开发环境。
  5. 再次尝试运行代码,现在应该可以正常运行。

答案 13 :(得分:3)

我实际上发现你可以使用最新的geckodriver而不是把它放在系统路径中。目前我正在使用

https://github.com/mozilla/geckodriver/releases/download/v0.12.0/geckodriver-v0.12.0-win64.zip

Firefox 50.1.0

Python 3.5.2

Selenium 3.0.2

Windows 10

我正在运行VirtualEnv(我使用PyCharm管理,我假设它使用Pip来安装所有内容)

在下面的代码中,我可以使用executable_path参数使用geckodriver的特定路径(我通过查看发现了这个 Lib \ site-packages \ selenium \ webdriver \ firefox \ webdriver.py)。注意我怀疑调用webdriver时参数参数的顺序很重要,这就是为什么executable_path在我的代码中的最后一行(最后一行到最右边)

您可能还会注意到我使用自定义的firefox配置文件来解决在您测试的网站具有不受信任的证书时将遇到的sec_error_unknown_issuer问题。见How to disable Firefox's untrusted connection warning using Selenium?

在调查后发现,木偶驱动程序不完整且仍在进行中,并且没有设置用于解雇或设置证书的各种功能或配置文件选项的数量。因此,使用自定义配置文件会更容易。

无论如何,这里的代码是关于我如何让geckodriver在没有路径的情况下工作:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

#you probably don't need the next 3 lines they don't seem to work anyway
firefox_capabilities['handleAlerts'] = True
firefox_capabilities['acceptSslCerts'] = True
firefox_capabilities['acceptInsecureCerts'] = True

#In the next line I'm using a specific FireFox profile because
# I wanted to get around the sec_error_unknown_issuer problems with the new Firefox and Marionette driver
# I create a FireFox profile where I had already made an exception for the site I'm testing
# see https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager

ffProfilePath = 'D:\Work\PyTestFramework\FirefoxSeleniumProfile'
profile = webdriver.FirefoxProfile(profile_directory=ffProfilePath)
geckoPath = 'D:\Work\PyTestFramework\geckodriver.exe'
browser = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, executable_path=geckoPath)
browser.get('http://stackoverflow.com')

答案 14 :(得分:2)

Selenium在他们的DESCRIPTION.rst

中回答了这个问题
Drivers
=======

Selenium requires a driver to interface with the chosen browser. Firefox,
for example, requires `geckodriver <https://github.com/mozilla/geckodriver/releases>`_, which needs to be installed before the below examples can be run. Make sure it's in your `PATH`, e. g., place it in `/usr/bin` or `/usr/local/bin`.

Failure to observe this step will give you an error `selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

基本上只需下载geckodriver,解压缩并将可执行文件移动到/ usr / bin文件夹

答案 15 :(得分:2)

这里有很多解决方案,其中大多数仍然通过手动下载软件包来使用手动方式。

最简单的解决方案实际上是from Navarasu

这里是例子;并且可以快速解决问题。

  1. 使用pip

    下载并安装软件包

    python -m pip安装webdriver-manager

示例

wolf@linux:~$ python -m pip install webdriver-manager
Collecting webdriver-manager
  Using cached https://files.pythonhosted.org/packages/9c/6c/b52517f34e907fef503cebe26c93ecdc590d0190b267d38a251a348431e8/webdriver_manager-3.2.1-py2.py3-none-any.whl
 ... output truncated ...
Installing collected packages: configparser, colorama, crayons, certifi, chardet, urllib3, idna, requests, webdriver-manager
Successfully installed certifi-2020.6.20 chardet-3.0.4 colorama-0.4.3 configparser-5.0.0 crayons-0.3.1 idna-2.10 requests-2.24.0 urllib3-1.25.9 webdriver-manager-3.2.1
wolf@linux:~$
  1. 在Python shell中执行
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

示例

wolf@linux:~$ python
Python 3.7.5 (default, Nov  7 2019, 10:50:52)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from selenium import webdriver
>>> from webdriver_manager.firefox import GeckoDriverManager
>>>
>>> driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
[WDM] - There is no [linux64] geckodriver for browser  in cache
[WDM] - Getting latest mozilla release info for v0.26.0
[WDM] - Trying to download new driver from https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
[WDM] - Driver has been saved in cache [/home/wolf/.wdm/drivers/geckodriver/linux64/v0.26.0]
>>>
  1. 将打开Web浏览器,在这种情况下为Firefox。

  2. 问题已解决。就是这样!

  3. 附加说明:如果您查看上面的日志,geckodriver是自动从https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz下载的,并保存到本地目录/home/wolf/.wdm/drivers/geckodriver/linux64/v0.26.0

  4. 您还可以复制此二进制文件并将其放在可从echo $PATH命令获取的任何可执行目录中。

例如

cp /home/$(whoami)/.wdm/drivers/geckodriver/linux64/v0.26.0/geckodriver /home/$(whoami)/.local/bin/

然后,让我们尝试https://pypi.org/project/selenium/

中的示例代码
from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
  1. 就是这样。

答案 16 :(得分:2)

我看到讨论仍在讨论通过下载二进制文件并手动配置路径来设置geckodriver的旧方法。

这可以使用webdriver-manager

自动完成
pip install webdriver-manager

现在问题中的上面的代码将在下面的更改中简单地工作,

from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

答案 17 :(得分:2)

Ubuntu 18.04+和最新版的geckodriver

这也适用于mac或其他* nix品种。

export GV=v0.24.0
wget "https://github.com/mozilla/geckodriver/releases/download/$GV/geckodriver-$GV-linux64.tar.gz"
tar xvzf geckodriver-$GV-linux64.tar.gz 
chmod +x geckodriver
sudo cp geckodriver /usr/local/bin/

答案 18 :(得分:2)

在Selenium / Python上发表的所有书籍以及通过谷歌发表的大部分评论都没有明确解释在Mac上设置这个问题的路径逻辑(一切都是Windows !! !!)。在&#34;&#34;&#34;&#34;&#34;你已经获得了路径设置(在我看来,便宜的出路!)。因此,对于精彩的Mac用户,请使用以下命令编辑bash路径文件:

&gt; $ touch~ / .bash_profile;打开〜/ .bash_profile

然后添加这样的路径.... *#为geckodriver设置PATH PATH =“在/ usr /斌/ geckodriver:$ {PATH}” 出口道路

为Selenium firefox设置PATH

PATH =“〜/用户/ yourNamePATH / VEnvPythonInterpreter / LIB / python2.7 /站点包/硒/ webdriver的/火狐/:$ {PATH}” 出口道路

在firefox驱动程序

上设置可执行文件的PATH

PATH =“/用户/ yournamePATH / VEnvPythonInterpreter / LIB / python2.7 /站点包/硒/ webdriver的/普通/ service.py:$ {PATH}” 出口路径*

这对我有用。我担心的是,Selenium Windows社区什么时候开始玩真实的游戏,并将Mac用户纳入他们傲慢的俱乐部会员资格。

答案 19 :(得分:1)

如果您使用的是 Linux

,则可以使用简单的命令来解决此问题
  1. 首先,下载(https://github.com/mozilla/geckodriver/releases)并解压缩ZIP文件

  2. 打开提取的文件夹

  3. 从文件夹(解压缩后geckodriver文件所在的文件夹)中打开终端

    Enter image description here

  4. 现在在终端上运行以下简单命令,将geckodriver复制到正确的文件夹中:

     sudo cp geckodriver /usr/local/bin
    

答案 20 :(得分:1)

对我来说,仅在同一环境中安装geckodriver就足够了:

$ brew install geckodriver

代码未更改:

from selenium import webdriver
browser = webdriver.Firefox()

答案 21 :(得分:0)

在Windows 10上,我可以下载geckodriver.exe。我只需要更新Firefox。

在我使用的代码下面:

from selenium import webdriver
driver = webdriver.Firefox(
    executable_path=r'C:\Users\Usuario\Desktop\Automate the boring stuff with python exercises\Web Scraping\geckodriver.exe')
driver.get('http://inventwithpython.com')

答案 22 :(得分:0)

这个错误信息...

FileNotFoundError: [WinError 2] The system cannot find the file specified

...表示您的程序无法找到指定的文件,并且在处理异常时发生了以下异常:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

... 这意味着您的程序在启动/生成新的浏览上下文(即 Firefox 浏览器 会话)的过程中无法定位 GeckoDriver .


您可以从 GeckoDriver 下载最新的 mozilla / geckodriver,解压/解压并将 GeckoDriver 二进制文件/可执行文件存储在系统中的任何位置,并传递 GeckoDriver 的绝对路径通过 key executable_path 如下:

from selenium import webdriver

driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
driver.get('http://google.com/')

如果 未安装在默认位置(即安装在自定义位置),您还需要通过属性 firefox 传递 binary_location 二进制文件的绝对路径,如下所示:

# An Windows example
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get('http://google.com/')

答案 23 :(得分:0)

我在将路径添加到“环境变量”后解决了这个问题。

`from selenium import webdriver

browser= webdriver.Firefox(executable_path='C:\ProgramData\Anaconda3\geckodriver.exe')

url = "https://github.com"

browser.close()`

答案 24 :(得分:0)

对于 Ubuntu 16.04+ 版本,您可以执行以下操作:-

对于火狐: -
sudo apt-get install firefox-geckodriver

对于 Chrome:-
sudo apt-get install chromium-chromedriver

答案 25 :(得分:0)

要加两分钱,也可以执行echo PATH(Linux)并将geckodriver移到您喜欢的文件夹中。如果将系统(而非虚拟环境)文件夹作为目标文件夹,则驱动程序变得可以全局访问。

答案 26 :(得分:0)

这个答案完全复制自: 科里·戈德堡@https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu

去给他投票

在 Ubuntu 上安装 geckodriver 的手动步骤:

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

下载最新版本的“geckodriver-vX.XX.X-linux64.tar.gz”

解压压缩包 (tar -xvzf geckodriver-vX.XX.X-linux64.tar.gz)

赋予 geckodriver 可执行权限 (chmod +x geckodriver)

将 geckodriver 二进制文件移动到 /usr/local/bin 或系统路径上的任何位置。

在 Ubuntu 上安装 geckodriver 的脚本:

#!/bin/bash

INSTALL_DIR="/usr/local/bin"

json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
curl -s -L "$url" | tar -xz
chmod +x geckodriver
sudo mv geckodriver "$INSTALL_DIR"
echo "installed geckodriver binary in $INSTALL_DIR"

答案 27 :(得分:0)

如果使用虚拟环境和win10(可能是其他系统的),则只需将geckodriver.exe放入虚拟环境目录中的以下文件夹中即可:

... \ my_virtual_env_directory \ Scripts \ geckodriver.exe

答案 28 :(得分:0)

  1. 确保您具有正确版本的驱动程序(geckodriver),x86或64。
  2. 确保您正在检查正确的环境,例如,作业在Docker中运行,而检查环境是主机OS

答案 29 :(得分:0)

from webdriverdownloader import GeckoDriverDownloader # vs ChromeDriverDownloader vs OperaChromiumDriverDownloader
gdd = GeckoDriverDownloader()
gdd.download_and_install()
#gdd.download_and_install("v0.19.0")

答案 30 :(得分:0)

如果要在Windows 10上添加驱动程序路径:

  1. 右键单击“此PC”图标,然后选择“属性” enter image description here

  2. 单击“高级系统设置”

  3. 点击屏幕底部的“环境变量”
  4. 在“用户变量”部分中,突出显示“路径”,然后单击“编辑”
  5. 通过单击“新建”并输入要添加的驱动程序的路径并按Enter键,将路径添加到变量中。
  6. 完成输入路径后,单击“确定”
  7. 持续单击“确定”,直到关闭所有屏幕

答案 31 :(得分:0)

  

对于Windows用户

按原样使用原始代码:

from selenium import webdriver
browser = webdriver.Firefox()
driver.get("https://www.google.com")

然后从以下位置下载驱动程序:mozilla/geckodriver

(永久地)将其放置在固定路径中。例如,我将其放置在:

  

C:\ Python35

然后转到系统的环境变量,在“系统变量”的网格中查找Path变量并添加:

  

; C:\ Python35 \ geckodriver

geckodriver,不是geckodriver.exe

答案 32 :(得分:0)

我正在使用Windows 10和Anaconda2。我尝试设置系统路径变量,但没有成功。然后我只是将geckodriver.exe文件添加到Anaconda2 / Scripts文件夹中,现在一切正常。 对我来说,路径是: -

C:\用户\巴维亚\ Anaconda2 \脚本

答案 33 :(得分:0)

访问Gecko Driver从下载部分获取gecko驱动程序的网址。

克隆此回购https://github.com/jackton1/script_install.git

cd script_install

运行

./installer --gecko-driver url_to_gecko_driver

答案 34 :(得分:0)

在Raspberry Pi上,我必须使用ARM驱动程序创建并在以下位置设置geckodriver和日志路径:

sudo nano /usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py

{{1}}

答案 35 :(得分:0)

Mac 10.12.1 python 2.7.10 这项工作对我来说:))

def download(url):
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
browser = webdriver.Firefox(capabilities=firefox_capabilities,
                            executable_path=r'/Users/Do01/Documents/crawler-env/geckodriver')
browser.get(url)
return browser.page_source