当前位置:   article > 正文

使用Selenium时出现报错(找不到浏览器驱动异常):NoSuchDriverException(msg) from err selenium.common.exceptions....._raise nosuchdriverexception(msg) from err

raise nosuchdriverexception(msg) from err

报错详情

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
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述

  • 以上报错是没有找到浏览器驱动,但实际上,我们已经下载好了驱动的,只不过可能位置没有放对或者是不知道该放哪里才好。

解决办法

很简单直接的解决方法就是我们直接指定浏览器驱动的位置即可。

from selenium import webdriver
# 启动浏览器
service = webdriver.EdgeService(executable_path='./msedgedriver.exe')   # 指定驱动的路径
driver = webdriver.Edge(service=service) 
  • 1
  • 2
  • 3
  • 4

完整的Selenium爬虫小示例

from selenium import webdriver
# https://zhuanlan.zhihu.com/p/557463669
# 启动浏览器
service = webdriver.EdgeService(executable_path='./msedgedriver.exe')
driver = webdriver.Edge(service=service)

# 打开目标网页
target_url = "https://boot-video.xuexi.cn/video/1006/p/5fd0919e562a1eedd1a8f740849f491a-72ee9dcf0fa440d7b8974dbea2538d39-2.mp4"
driver.get(target_url)

# 页面操作
driver.set_window_size(480, 800) # 页面大小
driver.back()    # 后退
driver.forward()  # 前进
driver.refresh()  # 刷新
driver.save_screenshot("./1.png")  # 页面截图
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

参考:https://www.selenium.dev/documentation/webdriver/drivers/service/#driver-location
示例参考:https://zhuanlan.zhihu.com/p/557463669

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

闽ICP备14008679号