我在python上运行selenium并安装了firefox。
当我尝试用硒打开firefox时,我遇到了一个令人讨厌的错误。我的代码在我的主机上运行正常(win10),但是当我在虚拟机(win7)上运行时,我收到此错误:
"C:\Program Files (x86)\Python35-32\python.exe" C:/Users/win7.PC/Desktop/Kijiji/kijiji.py
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\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 "C:/Users/win7.PC/Desktop/Kijiji/kijiji.py", line 408, in <module>
driver = webdriver.Firefox()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Program Files (x86)\Python35-32\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 0x02963690>>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Process finished with exit code 1
我升级了python,selenium,我尝试使用Firefox 47,46甚至28 :(
我试图改变路径:
from selenium import webdriver
driver = webdriver.Firefox(path="C:\Program Files (x86)\Mozilla Firefox\Firefox.exe")
它表明&#39;路径&#39;不是有效的输入
尝试更改二进制路径,如下所示:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
还是同样的问题。
有人有任何建议吗?