如何安装壁虎?

2024-04-20 02:52:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python中的Selenium。但是,我不知道从https://pypi.python.org/pypi/selenium开始下面的操作

Selenium需要一个驱动程序来与所选浏览器交互。例如,Firefox需要geckodriver,在运行下面的示例之前需要安装该程序。确保它在您的路径中,例如,将它放在/usr/bin or /usr/local/bin

我运行的是32位Windows7。我在这里找到壁虎:https://github.com/mozilla/geckodriver/releases

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

谢谢

更新

我更新了注释中显示的路径。这是完整的错误回溯。

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 init self.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 init self.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 init restore_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


Tags: inpyselfliblocalseleniumlinefirefox
3条回答

一些选项,请选择1:

  • 将exe文件移到PATH环境变量中的文件夹中。
  • 更新PATH以获得包含exe的目录。
  • 显式重写os.environ["webdriver.gecko.driver"]

基本上,将geckodriver拖放到可执行文件所在的位置,然后就可以打开命令行并使用它了。

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

见:

特别是关于司机的解释, 它可以放在哪里,以及如何修改selenium找到它的方式。

  1. 你可以下载geckodriver
  2. 把它解开
  3. 复制该.exe文件并将其放入python父文件夹(例如,C:\Python34
  4. 写你的剧本。

它将成功执行。

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

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

示例:

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

相关问题 更多 >