selenium+python 调起浏览器报错raise WebDriverException("Can not connect to the Service %s" % self.path)

本文介绍了一个常见的WebDriver异常问题,即无法连接到服务的情况,并提供了解决方案,通过在本地hosts文件中添加127.0.0.1 localhost条目来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

raise WebDriverException(“Can not connect to the Service %s” % self.path)

原因:本地hosts解析少 127.0.0.1 localhost,加上就就行

F:\PM\PycharmProjects\demo1\venv\Scripts\python.exe F:/PM/PycharmProjects/demo1/venv/demo1.py Traceback (most recent call last): File "F:\PM\PycharmProjects\demo1\venv\lib\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 "F:\PM\PycharmProjects\demo1\venv\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 90, in driver_location output = self.run(args) File "F:\PM\PycharmProjects\demo1\venv\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 138, in run raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}") selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: F:\PM\PycharmProjects\demo1\venv\lib\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_139_WINDOWS): error trying to connect: dns error: 不知道这样的主机。 (os error 11001)', 'driver_path': '', 'browser_path': ''} The above exception was the direct cause of the following exception: Traceback (most recent call last): File "F:/PM/PycharmProjects/demo1/venv/demo1.py", line 4, in <module> driver = webdriver.Edge() #启动 File "F:\PM\PycharmProjects\demo1\venv\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 50, in __init__ keep_alive, File "F:\PM\PycharmProjects\demo1\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in __init__ self.service.path = DriverFinder.get_path(self.service, options) File "F:\PM\PycharmProjects\demo1\venv\lib\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 pycharm用selenium调用Edge浏览器的Webdriver失败
最新发布
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值