解决selenium webdriver模块的网页加载问题

问题描述

当尝试测试运行selenium模块加载浏览器时

from selenium import webdriver
driver = webdriver.Edge()
driver.get("http://www.baidu.com/")

出现了如下错误:在这里插入图片描述

原因分析

该Exception明确指出需要将指定的driver(我这里是edgedriver)放到PATH中。对于driver下载链接如下:

Chrome: http://chromedriver.storage.googleapis.com/index.html

Edge:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

Firefox:https://github.com/mozilla/geckodriver/releases/

解决方案

from selenium import webdriver
option = webdriver.EdgeOptions()
option.binary_location = r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'	#这里添加edge的启动文件=>chrome的话添加chrome.exe的绝对路径
driver = webdriver.Edge(r'C:\Users\Allen\AppData\Local\Programs\Python\Python39\edgedriver_win64\msedgedriver.exe', options=option)	#这里添加的是driver的绝对路径
driver.get("http://www.baidu.com/")

如上处理之后,页面就能正常打开在这里插入图片描述

参考

https://blog.csdn.net/sonnyuu/article/details/110232247

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐