报错详情
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
- 以上报错是没有找到浏览器驱动,但实际上,我们已经下载好了驱动的,只不过可能位置没有放对或者是不知道该放哪里才好。
解决办法
很简单直接的解决方法就是我们直接指定浏览器驱动的位置即可。
from selenium import webdriver # 启动浏览器 service = webdriver.EdgeService(executable_path='./msedgedriver.exe') # 指定驱动的路径 driver = webdriver.Edge(service=service)
完整的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") # 页面截图
参考:https://www.selenium.dev/documentation/webdriver/drivers/service/#driver-location
示例参考:https://zhuanlan.zhihu.com/p/557463669
还没有评论,来说两句吧...