尝试对 Microsoft Edge 使用 selenium 时出现 NoSuchDriverException 错误

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

我正在尝试使用 Selenium 和 Microsoft Edge 来抓取数据,但我不断收到此错误消息。

PS C:\Users\Queensley\Desktop\hustle> python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> browser = webdriver.Edge()
Traceback (most recent call last):
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 94, in driver_location
    output = self.run(args)
             ^^^^^^^^^^^^^^
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 140, in run
    raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}")
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser MicrosoftEdge --output json.
{'code': 65, 'message': 'error sending request for url (https://msedgedriver.azureedge.net/LATEST_RELEASE_119_WINDOWS): error trying to connect: dns error: No such host is known. (os error 11001)', 'driver_path': '', 'browser_path': ''}

上述异常是导致以下异常的直接原因:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\edge\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Queensley\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for MicrosoftEdge using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

在 Microsoft Edge 上使用 Selenium 从网页中抓取数据。

python selenium-webdriver web-scraping microsoft-edge
1个回答
0
投票

您的堆栈跟踪会告诉您访问 https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location 以了解有关您所遇到的

NoSuchDriverException
的更多信息。

为了驱动 Microsoft Edge,Selenium 需要通过可执行驱动程序向其发送命令。此错误意味着 Selenium 尝试使用的任何方法都无法找到必要的驱动程序。

要解决这个问题,您有很多选择。您可以使用最新版本的 Selenium、使用 PATH 环境变量或下载 Edge 驱动程序。我鼓励您访问该链接并浏览其中建议的解决方案。请务必选择 Python,因为这是您正在使用的语言,并且选择 Windows,因为您似乎正在使用它。

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