Selenium WebDriver 的 Microsoft Edge 驱动程序【附代码】

1、从 Microsoft Edge 驱动程序的官方网站下载与浏览器版本相匹配的驱动程序。

https://msedgewebdriverstorage.z22.web.core.windows.net/https://msedgewebdriverstorage.z22.web.core.windows.net/

2、指向驱动程序(**msedgedriver.exe)**的路径

复制代码
service = Service('./msedgedriver.exe')

3、启动驱动程序

复制代码
browser = webdriver.Edge(service=service, options=options) 

4、关闭浏览器会话

复制代码
browser.quit()

例如:

startBrowser 方法

Python 类中用于初始化和启动 Microsoft Edge 浏览器会话的一个成员函数,这个方法使用了 Selenium WebDriver 来创建和配置浏览器实例

复制代码
     def startBrowser(self):
        service = Service('./msedgedriver.exe')
        options = webdriver.EdgeOptions()  # 创建浏览器选项实例
        options.add_experimental_option('excludeSwitches', ['enable-automation'])
        browser = webdriver.Edge(service=service, options=options)
        # 使用 webdriver.Edge 与 service 和 options 一起创建了一个新的 Edge 浏览器实例

        return browser
相关推荐
财经资讯数据_灵砚智能几秒前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月14日
人工智能·python·信息可视化·自然语言处理·ai编程
2303_821287382 分钟前
Redis如何监控系统QPS的变化趋势
jvm·数据库·python
dinglu1030DL3 分钟前
uni-app怎么接极光推送 uni-app消息推送App端接入【教程】
jvm·数据库·python
神明9315 分钟前
Go语言如何用logrus_Go语言logrus日志框架教程【技巧】
jvm·数据库·python
2301_7796224111 分钟前
PHP处理Codex安全漏洞检测【解答】
jvm·数据库·python
cndes20 分钟前
Pycharm的虚拟环境设置问题
开发语言·python
HungryGoogle21 分钟前
【无标题】
python·网络安全
weixin_4597539429 分钟前
c++如何利用filesystem--relative计算两个文件之间的相对路径【详解】
jvm·数据库·python
jekc86837 分钟前
金蝶云星空调用第三方接口
开发语言·python
才兄说42 分钟前
机器人二次开发机器狗巡检?自动生成巡检日志
python