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
相关推荐
leisoo80975 分钟前
涨停板次日表现因子怎么挖掘本地化Python全流程实战
大数据·人工智能·python
像颗糖5 分钟前
AG-UI:把 Agent 与前端之间的“私有暗号”变成标准协议
python·agent·ai编程
Zane199411 分钟前
类也是对象?一文讲透元类 metaclass 这件"深度魔法"
后端·python
Fanta丶12 分钟前
3.FastAPI ORM建表
python
云水初33 分钟前
【agent篇】RAG 知识库构建避坑指南
开发语言·python·学习·agent·rag
2019一路前行35 分钟前
Python 函数、循环语句
开发语言·python
qxqycb1 小时前
python一键反编译工具
python
weixin_BYSJ19871 小时前
springboot技能与工具共享小程序---附源码29657
java·javascript·spring boot·python·小程序·django·php
weixin_BYSJ19872 小时前
flask民族服饰饰品商城小程序---附源码37399
java·javascript·spring boot·python·小程序·django·php
帅气的小峰2 小时前
pybind11与nanobind可以共存吗?如何迁移?
c++·python·cuda·推理引擎