浏览器问题= webdriver.Firefox()

问题描述 投票:0回答:2

我的代码(例如来自此处https://pypi.org/project/selenium/

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

错误

Traceback (most recent call last):
  File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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 "D:\Project\python-work\website.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

有人知道这个问题/修复吗?

python python-3.x windows selenium-webdriver firefox
2个回答
1
投票

您收到此错误是因为您没有适用于 Firefox 的 selenium Web 驱动程序。

要获取它,请访问网站 https://github.com/mozilla/geckodriver/releases

下载适合您操作系统的版本。

提取它

将提取的文件放在运行此脚本的同一目录中。

即您的“website.py”文件必须与提取的文件位于同一目录中

维奥拉!!!


0
投票

此处的错误是因为无法使用 Firefox Web 驱动程序。

您可以通过 2 种方式获得司机,

  1. 访问此网站适用于 python 的 Firefox Web 驱动程序,并下载最新版本的 Web 驱动程序,但这将帮助您仅在您的语言环境上运行代码,每次您在另一台计算机上运行代码时,它都会要求重写您为网络驱动程序提供的路径。如果您尚未将 .exe 文件包含在项目文件夹中。

  2. 更好的方法是熟悉webdriver管理器python,这使得你的代码更加可移植和健壮,这可以帮助你自动设置你需要的驱动程序。这种方法将帮助您从一开始就编写高效的代码。

© www.soinside.com 2019 - 2024. All rights reserved.