我正在尝试使用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
一些选项,请选择1:
PATH
环境变量中的文件夹中。PATH
以获得包含exe的目录。os.environ["webdriver.gecko.driver"]
基本上,将geckodriver拖放到可执行文件所在的位置,然后就可以打开命令行并使用它了。
在linux上,
/bin
,和C:\Program Files
见:
特别是关于司机的解释, 它可以放在哪里,以及如何修改selenium找到它的方式。
C:\Python34
)它将成功执行。
如果您在windows上,最简单的方法是:
示例:
相关问题 更多 >
编程相关推荐