Python 使用Selenium打开浏览器时获取异常

Python 使用Selenium打开浏览器时获取异常,python,python-2.7,selenium,scripting,automation,Python,Python 2.7,Selenium,Scripting,Automation,我正在使用pythonidle,在执行以下命令之后,我得到了这个导入错误 >>> from selenium import webdriver >>> browser=webdriver.Firefox() Traceback (most recent call last): File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium

我正在使用pythonidle,在执行以下命令之后,我得到了这个导入错误

>>> from selenium import webdriver
>>> browser=webdriver.Firefox()


Traceback (most recent call last):
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\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#18>", line 1, in <module>
    browser=webdriver.Firefox()
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\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.
来自selenium导入webdriver的
>
>>>browser=webdriver.Firefox()
回溯(最近一次呼叫最后一次):
文件“C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site packages\selenium\webdriver\common\service.py”,第74行,开头
stdout=self.log\u文件,stderr=self.log\u文件)
文件“C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py”,第947行,在uu init中__
恢复信号,启动新会话)
文件“C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py”,第1224行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
browser=webdriver.Firefox()
文件“C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site packages\selenium\webdriver\firefox\webdriver.py”,第144行,在uu init中__
self.service.start()
文件“C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site packages\selenium\webdriver\common\service.py”,第81行,在开始处
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要位于路径中。

您的例外情况很清楚:

WebDriverException:消息:“geckodriver”可执行文件需要在 路径

您必须指定geckodriver的路径:

driver = webdriver.Firefox(executable_path=r'/patToYour/geckodriver')