如何安装适用于Windows的Firefox Web驱动程序?



如何安装 Firefox Web 驱动程序以使用 Selenium\python

我用命令安装了它

pip install selenium

我尝试了以下代码:

driver=webdriver.Firefox()
driver.get("https://www.google.com")
content=driver.find_element_by_id("lga")
print(content)

但它给了我这个错误

Traceback (most recent call last):
File "C:UsersAcerAppDataLocalProgramsPythonPython37-32libsite-package
sseleniumwebdrivercommonservice.py", line 76, in start
stdin=PIPE)
File "C:UsersAcerAppDataLocalProgramsPythonPython37-32libsubprocess.p
y", line 775, in __init__
restore_signals, start_new_session)
File "C:UsersAcerAppDataLocalProgramsPythonPython37-32libsubprocess.p
y", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".Class.py", line 3, in <module>
class Scrape:
File ".Class.py", line 4, in Scrape
driver = webdriver.Firefox()
File "C:UsersAcerAppDataLocalProgramsPythonPython37-32libsite-package
sseleniumwebdriverfirefoxwebdriver.py", line 164, in __init__
self.service.start()
File "C:UsersAcerAppDataLocalProgramsPythonPython37-32libsite-package
sseleniumwebdrivercommonservice.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable
needs to be in PATH.

有几件事要检查一下。

1(您需要确保已安装火狐浏览器。
2(在此处
获取最新的壁虎驱动程序 3(在您的环境中
设置路径

export PATH=$PATH:/path/to/directory/of/executable/geckodriver<br>

4(如果你打算跳过3,你需要在你的脚本
中修改它

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:FirefoxFirefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)

最新更新