【问题标题】:how to install Firefox web driver for windows?如何为 Windows 安装 Firefox 网络驱动程序?
【发布时间】:2019-10-19 12:37:28
【问题描述】:

如何安装 Firefox 网络驱动程序以使用 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:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.p
y", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.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:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.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.

【问题讨论】:

标签: python-3.x windows selenium selenium-webdriver webdriver


【解决方案1】:

有几件事要检查。

1) 您需要确保已安装 Firefox。
2) 获取最新的壁虎驱动here
3) 在您的环境中设置路径

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

4) 如果您打算跳过 3 ,则需要在脚本中修改此内容

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)

【讨论】:

  • 即使我对环境中的路径执行了 webdriver,但它对我不起作用,但这行代码解决了它: driver = webdriver.Firefox(executable_path=r'C:\webdriver\ geckodriver.exe') 无论如何谢谢你的帮助
猜你喜欢
  • 2018-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-16
  • 2011-07-02
  • 2011-12-11
  • 2014-06-23
相关资源
最近更新 更多