Python 如何安装 Geckodriver?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41190989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:32:13  来源:igfitidea点击:

How do I install Geckodriver?

pythonseleniumpathwebautomationgeckodriver

提问by polonius11

I am attempting to work with Seleniumin Python. However, I do not know what to do given the below from https://pypi.python.org/pypi/selenium

我正在尝试Selenium在 Python 中使用。但是,根据https://pypi.python.org/pypi/selenium的以下内容,我不知道该怎么做

Seleniumrequires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, 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.

Selenium需要一个驱动程序来与所选浏览器进行交互。例如,Firefoxgeckodriver需要安装它,然后才能运行以下示例。确保它在您的 PATH 中,例如,将它放在/usr/bin or /usr/local/bin.

I am running windows 7 32bit. I found geckodriver here: https://github.com/mozilla/geckodriver/releases

我正在运行 Windows 7 32 位。我在这里找到了 geckodriver:https: //github.com/mozilla/geckodriver/releases

I have mostly used the Anaconda distribution of Python to work with excel so I do not know what is a "PATH"

我主要使用 Python 的 Anaconda 发行版来处理 excel,所以我不知道什么是“路径”

Thanks,

谢谢,

UPDATE:

更新

I updated the PATH as shown in the comments. Here is the full error traceback.

我更新了 PATH,如评论中所示。这是完整的错误回溯。

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\user1>python

Python 3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul 5 2016, 11:45:57) [MSC v.1 900 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

from selenium import webdriver
driver = webdriver.Firefox()

Traceback (most recent call last):

File "", line 1, in

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\webdriver.py", li ne 80, in initself.binary, timeout)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\extension_connect ion.py", line 52, in initself.binary.launch_browser(self.profile, timeout=timeout)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py ", line 67, in launch_browser self._start_from_profile_path(self.profile.path)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py ", line 90, in _start_from_profile_path env=self._firefox_env)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py", line 947, in initrestore_signals, start_new_session)

File "C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py", line 1224, in _execute_child startupinfo)

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

Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。版权所有。

C:\Users\user1>python

Python 3.5.2 |Anaconda 4.2.0(32 位)| (默认,2016 年 7 月 5 日,11:45:57)win32 上的 [MSC v.1 900 32 位(英特尔)]

输入“帮助”、“版权”、“信用”或“许可”以获取更多信息。

from selenium import webdriver
driver = webdriver.Firefox()

回溯(最近一次调用最后一次):

文件“”,第 1 行,在

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\webdriver.py”,第80行,在initself.binary 中,超时)

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\extension_connect ion.py”,第 52 行,在initself.binary.launch_browser(self.profile, timeout=timeout)

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py”,第 67 行,在launch_browser self._start_from_profile_path(self.profile.path)

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py”,第 90 行,在_start_from_profile_path env=self._firefox_env)

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py”,第 947 行,在initrestore_signals、start_new_session 中)

文件“C:\Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py”,第 1224 行,在 _execute_child startupinfo 中)

FileNotFoundError: [WinError 2] 系统找不到指定的文件

回答by jayesh

  1. You can download the geckodriver
  2. unzip it
  3. Copy that .exe file and put your into python parent folder (e.g., C:\Python34)
  4. write your scripts.
  1. 你可以下载geckodriver
  2. 解压
  3. 复制该 .exe 文件并将您的放入 python 父文件夹(例如,C:\Python34
  4. 编写脚本。

It will execute successfully.

它将成功执行。

回答by Iman

The easiest way if you are on windows:

如果您在 Windows 上,最简单的方法是:

driver = webdriver.Firefox(executable_path=r'[Your path]\geckodriver.exe')

Example:

例子:

driver = webdriver.Firefox(executable_path=r'D:\geckodriver.exe')

回答by Charles Santos

There is an easy way to install Geckodriver:

有一种安装 Geckodriver 的简单方法:

  1. Install webdrivermanagerwith pip

    pip install webdrivermanager

  2. Install the driver for Firefox and Chrome

    webdrivermanager firefox chrome --linkpath /usr/local/bin

  3. Or install the driver only for Firefox

    webdrivermanager firefox --linkpath /usr/local/bin

  4. Or install the driver only for Chrome

    webdrivermanager chrome --linkpath /usr/local/bin

  1. 安装webdrivermanager使用pip

    pip install webdrivermanager

  2. 安装 Firefox 和 Chrome 的驱动程序

    webdrivermanager firefox chrome --linkpath /usr/local/bin

  3. 或者只为 Firefox 安装驱动程序

    webdrivermanager firefox --linkpath /usr/local/bin

  4. 或仅安装适用于 Chrome 的驱动程序

    webdrivermanager chrome --linkpath /usr/local/bin

回答by jeppoo1

For me this worked (Windows 10, Firefox browser):

对我来说这是有效的(Windows 10,Firefox 浏览器):

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\......YOUR_PATH.......\geckodriver.exe')
driver.get('http://EXAMPLE_URL.com')

回答by jmunsch

Some options, choose 1:

一些选项,选择1:

  • Move the exe file to a folder in your PATHenvironment variable.
  • Update PATHto have the directory that contains the exe.
  • Explicitly override os.environ["webdriver.gecko.driver"]
  • 将 exe 文件移动到PATH环境变量中的文件夹。
  • 更新PATH以拥有包含 exe 的目录。
  • 显式覆盖 os.environ["webdriver.gecko.driver"]

basically drag and drop the geckodriver someplace where you have your executables, you should then be able to open the command line and use it.

基本上将 geckodriver 拖放到您拥有可执行文件的某个地方,然后您应该能够打开命令行并使用它。

/binon linux, and C:\Program Files

/bin在 linux 上,和 C:\Program Files

see:

看:

specifically the explanations on how the driver is seen, where it can be put ,and how to modify the way selenium finds it.

特别是关于如何看到驱动程序的解释,它可以放在哪里,以及如何修改 selenium 找到它的方式。

回答by NoobCoder

For Python 3 - Selenium plus webdriver for Firefox;

对于 Python 3 - Selenium 和用于 Firefox 的 webdriver;

  1. Open up Command line
  2. Enter Pip install -U Selenium(The -U will upgrade it to the latest Selenium version.) This example selenium is already installed

  3. Go to https://github.com/mozilla/geckodriver/releases

  4. At the time of writing I chose the latest version which was simply the version listed at the top of the page. For me it was v0.24.0.

  5. Scroll down to assets and then click and download the correct driver. For windows it will be a zip file. Most likely 64bit. Download the webdriver by clicking on the link5.Right click on the downloaded file and unzip the file.

  6. Copy and paste the file to somewhere in your python directory. e.g. If I installed Python in C:\Python\Python37 I would paste the file in there so gecko would be located in C:\Python\Python37\geckodriver-v0.24.0-win64

  1. 打开命令行
  2. 输入Pip install -U Selenium(-U 会升级到最新的 Selenium 版本。) 这个例子已经安装了 selenium

  3. 转到https://github.com/mozilla/geckodriver/releases

  4. 在撰写本文时,我选择了最新版本,即页面顶部列出的版本。对我来说是 v0.24.0。

  5. 向下滚动到资产,然后单击并下载正确的驱动程序。对于 Windows,它将是一个 zip 文件。最有可能是 64 位。 单击链接下载 webdriver5.右键单击下载的文件并解压缩文件。

  6. 将文件复制并粘贴到 python 目录中的某个位置。例如,如果我在 C:\Python\Python37 中安装了 Python,我会将文件粘贴在那里,因此 gecko 将位于 C:\Python\Python37\geckodriver-v0.24.0-win64

Copying the file path of the geckodriver

复制geckodriver的文件路径

  1. Inside that folder you just copied will be the geckodriver.exe

  2. In Windows 10, click the "windows" button and search "environment variables" Find environment variablesOR find it using these instructions; https://www.computerhope.com/issues/ch000549.htm

  3. Click on the "environment variables" box at the bottom right hand corner.

  4. In the bottom box "System Variables" highlight the "Path" variable like so Adding environment variable Path

  5. Press edit and then add the entry at the bottom of the list. Copy and paste the location where the geckodriver.exe file lives. For me it was C:\Python\Python37\geckodriver-v0.24.0-win64 (or where you copied the file in step 6) Adding gecko to the windows PATH

  1. 在您刚刚复制的文件夹中将是 geckodriver.exe

  2. 在 Windows 10 中,单击“windows”按钮并搜索“环境变量” 查找环境变量或使用这些说明查找它;https://www.computerhope.com/issues/ch000549.htm

  3. 单击右下角的“环境变量”框。

  4. 在底部框中的“系统变量”中突出显示“路径”变量,就像这样 添加环境变量路径

  5. 按编辑,然后在列表底部添加条目。复制并粘贴 geckodriver.exe 文件所在的位置。对我来说,它是 C:\Python\Python37\geckodriver-v0.24.0-win64(或您在第 6 步中复制文件的位置) 将壁虎添加到 Windows PATH

回答by kip2

If you're on macOS/Apple, you can use Homebrew: brew install geckodriver

如果您使用的是 macOS/Apple,则可以使用 Homebrew: brew install geckodriver

See this related question

看到这个相关问题