简体   繁体   English

浏览器问题 = webdriver.Firefox()

[英]problem with browser = webdriver.Firefox()

My code (from eg here https://pypi.org/project/selenium/ )我的代码(例如从这里https://pypi.org/project/selenium/

from selenium import webdriver从 selenium 导入 webdriver

browser = webdriver.Firefox()浏览器 = webdriver.Firefox()

Error 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错误回溯(最近一次调用最后):文件“C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py”,第 72 行,开始self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\subprocess.py",第 854 行,在init self._execute_child (args、可执行文件、preexec_fn、close_fds、文件“C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\subprocess.py”,第 1307 行,在 _execute_child hp、ht、pid、tid = _winapi 中。 CreateProcess(executable, args, FileNotFoundError: [WinError 2] 系统找不到指定的文件

During handling of the above exception, another exception occurred:在处理上述异常的过程中,又出现了一个异常:

Traceback (most recent call last): File "D:\Project\python-work\website.py", line 3, in 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.回溯(最后一次调用):文件“D:\Project\python-work\website.py”,第 3 行,在浏览器 = webdriver.Firefox() 文件“C:\Users\saltlake\AppData\Local\Programs\ Python\Python38\lib\site-packages\selenium\webdriver\firefox\webdriver.py”,第 164 行,在init self.service.start() 文件“C:\Users\saltlake\AppData\Local\Programs\Python\ Python38\lib\site-packages\selenium\webdriver\common\service.py",第 81 行,开始引发 WebDriverException(selenium.common.exceptions.WebDriverException:消息:'geckodriver' 可执行文件需要在 PATH 中。

Anybody aware this problem/fix?有人知道这个问题/修复吗?

You're getting this error because you don't have selenium web driver for firefox.您收到此错误是因为您没有 firefox 的 selenium web 驱动程序。

To get it, go to the website https://github.com/mozilla/geckodriver/releases要得到它,go 到网站https://github.com/mozilla/geckodriver/releases

Download the version suitable for your os.下载适合您操作系统的版本。

Extract it提取它

Place the extracted file in the same directory you're running this script.将提取的文件放在运行此脚本的同一目录中。

Ie your "website.py" file must be in the same directory as the extracted file即您的“website.py”文件必须与提取的文件位于同一目录中

Viola!!!中提琴!!!

The error here is for the unavailability of a firefox web driver to work with.此处的错误是因为无法使用 firefox web 驱动程序。

There are 2 ways you can have the driver,有两种方法可以获得驱动程序,

  1. Go to this website Firefox web driver for python , and download the latest version of the web driver, but that'll help you run the code on your locale only, everytime you run code on another machine it'll ask for rewriting the path you'll give for web driver. Go to this website Firefox web driver for python , and download the latest version of the web driver, but that'll help you run the code on your locale only, everytime you run code on another machine it'll ask for rewriting the path you '会给 web 驱动程序。 If you haven't included the.exe file in the project folder.如果您没有在项目文件夹中包含 .exe 文件。

  2. The better approach is to get familiarize with the webdriver manager python , which makes your code more portable and robust, which helps you set up the driver you need automatically.更好的方法是熟悉webdriver manager python ,它可以使您的代码更便携和健壮,从而帮助您自动设置所需的驱动程序。 This approach will help you write efficient codes at the beginning itself.这种方法将帮助您从一开始就编写高效的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM