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
相关推荐
全栈陈序员几秒前
【Python】基础语法入门(三十三)—— 日志系统详解:用 logging 记录程序运行
java·开发语言·python
晗夜未央9 分钟前
跨仓库 Skill 换台电脑就失效?用 Git remote 校验项目
人工智能·git·python
Zack_Liu14 分钟前
code样例
pytorch·python·深度学习
wusam18 分钟前
基于HCL的python脚本编程(4)
网络·python·智能路由器
treasure14020 分钟前
Django复习笔记(2026年10月)
后端·python·django·api·web·drf
xiaoqiangclub38 分钟前
Python 的实验性 JIT 要生变?那个开关现在还该不该开
python·性能优化·jit·开发环境·cpython
2601_9679873741 分钟前
终端 IDE 卷到了新高度:个人免费,符号索引快 65%,内存省 95%
ide·python·免费·性能·rune
全栈陈序员1 小时前
【Python】基础语法入门(三十一)—— API 开发:用 FastAPI 构建 RESTful 接口
python·restful·fastapi
懂点Tech9 小时前
ctfshow misc28:GIF 高度修改解题与脚本实现
开发语言·windows·python
comedate9 小时前
SMLib 的 Examples 导读:PyAPI / SM_API / SMLib 三组示例怎么读
python·cad·smlib·examples·sm_api