selenium启动报错:Microsoft Edge failed to start: exited normally. (chrome not reachable)

一、起因

今天打算用selenium跑个爬虫,下面是代码: 

from selenium import webdriver
from selenium.webdriver.edge.service import Service
import time

ser = Service("C:/YB/bin/msedgedriver.exe")
edge_options = webdriver.EdgeOptions()
edge_options.add_argument("user-data-dir=C:/Users/yuanb/AppData/Local/Microsoft/Edge/User Data")
edge_options.add_argument("profile-directory=Default")

driver = webdriver.Edge(service=ser, options=edge_options)
driver.get('https://bing.com')

time.sleep(20)
driver.quit()

最近因为Edge浏览器换成chromium内核后很好用,我就在换了新电脑后,没有装chrome,一直用Edge,于是就用Edge浏览器来跑,结果就给我报错了:

Traceback (most recent call last):
  File "C:\Users\yuanb\PycharmProjects\ChinaJudgementsOL\spider2.py", line 14, in <module>
    driver = webdriver.Edge(service=ser, options=edge_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\edge\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Microsoft Edge failed to start: exited normally.
  (chrome not reachable)
  (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
Stacktrace:
	GetHandleVerifier [0x00007FF6C3A35B82+59842]
	Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C4AB2+220434]
	(No symbol) [0x00007FF6C37EDCD7]
	(No symbol) [0x00007FF6C382043F]
	(No symbol) [0x00007FF6C381C2C0]
	(No symbol) [0x00007FF6C385DE97]
	(No symbol) [0x00007FF6C3853B93]
	(No symbol) [0x00007FF6C382960E]
	(No symbol) [0x00007FF6C38287CC]
	(No symbol) [0x00007FF6C38291C1]
	Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6C3BE58FC+1052188]
	(No symbol) [0x00007FF6C389FFC6]
	Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF6C394150C+37916]
	Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF6C3938E95+3493]
	Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6C3BE4865+1047941]
	Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39CD2C1+255265]
	Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C85B4+235540]
	Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C86EB+235851]
	Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39BFEE1+201025]
	BaseThreadInitThunk [0x00007FFB626E257D+29]
	RtlUserThreadStart [0x00007FFB63BAAA58+40]

二、解决

网上搜各种解决方案,最终找到了一个点:

需要在任务管理器中杀掉edge进程!!!

需要在任务管理器中杀掉edge进程!!!

需要在任务管理器中杀掉edge进程!!!

这让我想起了前几年写过的一篇博客,当时是用chrome浏览器,就是因为只关闭了chrome浏览器而没有杀掉chrome进程,也导致启动报错!好吧,同一个坑踩了两次。

 

 三、参考

1、python - MSEdge failed to start: crashed (chrome not reachable) - Stack Overflow 

2、selenium.webdriver unknow error:cannot connect to chrome at 127.0.0.1:9222-CSDN博客 

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值