在一本书上看到的例子,使用Firefox浏览器,打开百度网页,输入关键字进行搜索。照着例子把代码敲完,运行的时候报错。
代码如下:
#coding=utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.get("http://www.baidu.com") driver.find_element_by_id("kw").send_keys("Selenium2") driver.find_element_by_id("su").click() driver.quit()
报错信息如下:
>>> Traceback (most recent call last): File"C:\Python34\lib\site-packages\selenium\webdriver\common\service.py",line 74, in start stdout=self.log_file, stderr=self.log_file) File"C:\Python34\lib\subprocess.py", line 859, in __init__ restore_signals, start_new_session) File"C:\Python34\lib\subprocess.py", line 1112, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。 During handling of the above exception, anotherexception occurred: Traceback (most recent call last): File"D:/code/baidu.py", line 4, in <module> driver =webdriver.Firefox() File"C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",line 140, in __init__ self.service.start() File"C:\Python34\lib\site-packages\selenium\webdriver\common\service.py",line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException:Message: 'geckodriver' executable needs to be in PATH.
我是电脑是windowsXP,装的有Firefox浏览器。python以及selenium信息如下:
C:\Python34>pythonPython 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015,22:43:06) [MSC v.1600 32 bit (Intel)] on win32Type "help", "copyright","credits" or "license" for more information.>>> C:\Python34>pip show seleniumName: seleniumVersion: 3.0.2Summary: Python bindings for SeleniumHome-page: https://github.com/SeleniumHQ/selenium/Author: UNKNOWNAuthor-email: UNKNOWNLicense: UNKNOWNLocation: c:\python34\lib\site-packagesRequires: C:\Python34>pythonPython 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015,22:43:06) [MSC v.1600 32 bit (Intel)] on win32Type "help", "copyright","credits" or "license" for more information.>>>
请教,这是什么原因呢?为什么还是报找不到文件呢,系统装的有Firefox浏览器。
|