Python 带有selenium的webdriver.Firefox()出现错误

Python 带有selenium的webdriver.Firefox()出现错误,python,selenium,firefox,Python,Selenium,Firefox,我正在使用python 3.5、firefox 45(也尝试了49)和selenium 3.0.1 我试过: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() 然后我得到了错误信息: C:\Users\A\AppData\Local\Programs\Python\Python35\python.exe C:/Users/A/De

我正在使用python 3.5、firefox 45(也尝试了49)和selenium 3.0.1

我试过:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
然后我得到了错误信息:

C:\Users\A\AppData\Local\Programs\Python\Python35\python.exe
C:/Users/A/Desktop/car/test.py
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 1220, 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 "C:/Users/A/Desktop/car/test.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x0000000000EB8278>>
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
C:\Users\A\AppData\Local\Programs\Python\Python35\Python.exe
C:/Users/A/Desktop/car/test.py
回溯(最近一次呼叫最后一次):
文件“C:\Users\A\AppData\Local\Programs\Python\35\lib\site packages\selenium\webdriver\common\service.py”,第64行,在开始处
stdout=self.log\u文件,stderr=self.log\u文件)
文件“C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py”,第950行,在uu init中__
恢复信号,启动新会话)
文件“C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py”,第1220行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:/Users/A/Desktop/car/test.py”,第4行,在
driver=webdriver.Firefox()
文件“C:\Users\A\AppData\Local\Programs\Python\35\lib\site packages\selenium\webdriver\firefox\webdriver.py”,第135行,在\uu init中__
self.service.start()
文件“C:\Users\A\AppData\Local\Programs\Python\35\lib\site packages\selenium\webdriver\common\service.py”,第71行,在开始处
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要位于路径中。
在中忽略异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\A\AppData\Local\Programs\Python\35\lib\site packages\selenium\webdriver\common\service.py”,第163行,在__
self.stop()
文件“C:\Users\A\AppData\Local\Programs\Python\35\lib\site packages\selenium\webdriver\common\service.py”,第135行,在stop中
如果self.process为无:
AttributeError:“服务”对象没有属性“进程”

我能做什么?非常感谢您的帮助

如果您使用的是firefox版本>47.0.1,您需要在系统路径中具有
[geckodriver][1]
可执行文件。对于早期版本,您希望禁用木偶。你可以这样做:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['marionette'] = False
driver = webdriver.Firefox(capabilities=capabilities)

谢谢迪安·芬斯特!我得到了:TypeError:\uuuu init\uuuuuu()得到了一个意外的关键字参数“所需的功能”