当前位置:   article > 正文

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

selenium chrome not reachable

一、起因

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

  1. from selenium import webdriver
  2. from selenium.webdriver.edge.service import Service
  3. import time
  4. ser = Service("C:/YB/bin/msedgedriver.exe")
  5. edge_options = webdriver.EdgeOptions()
  6. edge_options.add_argument("user-data-dir=C:/Users/yuanb/AppData/Local/Microsoft/Edge/User Data")
  7. edge_options.add_argument("profile-directory=Default")
  8. driver = webdriver.Edge(service=ser, options=edge_options)
  9. driver.get('https://bing.com')
  10. time.sleep(20)
  11. driver.quit()

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

  1. Traceback (most recent call last):
  2. File "C:\Users\yuanb\PycharmProjects\ChinaJudgementsOL\spider2.py", line 14, in <module>
  3. driver = webdriver.Edge(service=ser, options=edge_options)
  4. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  5. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\edge\webdriver.py", line 45, in __init__
  6. super().__init__(
  7. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 61, in __init__
  8. super().__init__(command_executor=executor, options=options)
  9. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 208, in __init__
  10. self.start_session(capabilities)
  11. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 292, in start_session
  12. response = self.execute(Command.NEW_SESSION, caps)["value"]
  13. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  14. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 347, in execute
  15. self.error_handler.check_response(response)
  16. File "C:\YB\Software\anaconda3\envs\selenium\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
  17. raise exception_class(message, screen, stacktrace)
  18. selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Microsoft Edge failed to start: exited normally.
  19. (chrome not reachable)
  20. (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.)
  21. Stacktrace:
  22. GetHandleVerifier [0x00007FF6C3A35B82+59842]
  23. Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C4AB2+220434]
  24. (No symbol) [0x00007FF6C37EDCD7]
  25. (No symbol) [0x00007FF6C382043F]
  26. (No symbol) [0x00007FF6C381C2C0]
  27. (No symbol) [0x00007FF6C385DE97]
  28. (No symbol) [0x00007FF6C3853B93]
  29. (No symbol) [0x00007FF6C382960E]
  30. (No symbol) [0x00007FF6C38287CC]
  31. (No symbol) [0x00007FF6C38291C1]
  32. Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6C3BE58FC+1052188]
  33. (No symbol) [0x00007FF6C389FFC6]
  34. Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF6C394150C+37916]
  35. Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF6C3938E95+3493]
  36. Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6C3BE4865+1047941]
  37. Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39CD2C1+255265]
  38. Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C85B4+235540]
  39. Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39C86EB+235851]
  40. Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6C39BFEE1+201025]
  41. BaseThreadInitThunk [0x00007FFB626E257D+29]
  42. 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博客 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/950129
推荐阅读
相关标签
  

闽ICP备14008679号