selenium启用MS Edge浏览器/下载MS Edge WebDriver

Selenium 是一个用于自动化 web 浏览器的工具,可以用于测试 web 应用程序或执行特定 web 任务。要在 Python 中使用 Selenium 来控制 Edge 浏览器,您需要安装相应的 Selenium 包和 Edge 驱动程序,并编写相应的 Python 代码。

# 创建 selenium Edge 浏览器的选项对象
options = Options()
# 设置浏览器的二进制路径
options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
# 创建 Edge WebDriver,并传入选项
driver = webdriver.Edge(options=options)

selenium Microsoft Edge浏览器驱动: Microsoft Edge WebDriver | Microsoft Edge Developer

from selenium import webdriver
from selenium.webdriver.edge.options import Options
import time
# 创建 seleniumEdge 浏览器的选项对象
options = Options()

# 设置浏览器的二进制路径
options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"


# 创建 Edge WebDriver,并传入选项
driver = webdriver.Edge(options=options)

# 执行其他操作
driver.get("https://www.example.com")

# 等待5秒钟
time.sleep(5)

# 获取页面的 HTML 内容
html_content = driver.page_source

# 打印 HTML 内容
print(html_content)

# 关闭浏览器
driver.quit()

import time
from selenium import webdriver
from selenium.webdriver.edge.service import Service

# 设置 Edge 浏览器驱动程序的路径
edge_driver_path = "C:\\Program Files (x86)\\Microsoft\\Edge\\edgedriver_win64\\msedgedriver.exe"

# 创建 Edge 浏览器服务
service = Service(edge_driver_path)
service.start()

# 创建 Edge 浏览器的配置选项
options = webdriver.EdgeOptions()
options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
options.set_capability("ms:loggingPrefs", {"browser": "ALL"})

# 创建 Edge WebDriver,并传入选项和服务
driver = webdriver.Edge(service=service, options=options)

# 打开网页
driver.get("https://www.example.com")

# 等待5秒钟
time.sleep(5)

# 获取浏览器日志
logs = driver.get_log("browser")
for log in logs:
    print(log)

# 获取页面的 HTML 内容
html_content = driver.page_source

# 打印 HTML 内容
print(html_content)

# 关闭浏览器和服务
driver.quit()
service.stop()

也可以加入系统PATH:
浏览器  C:\Program Files (x86)\Microsoft\Edge\Application
WebDriver驱动文件位置: C:\Program Files (x86)\Microsoft\Edge\edgedriver_win64
-----

# 设置 Edge 浏览器驱动程序的路径
edge_driver_path = "path_to_your_edgedriver.exe"  # 请将路径替换为您下载的 Edge 驱动程序的实际路径

# 创建 Edge 浏览器的配置选项
options = webdriver.EdgeOptions()
options.binary_location = "path_to_your_edge_binary"  # 如果需要指定 Edge 可执行文件的路径,请替换为实际路径
# 更多配置选项,例如设置代理、设置浏览器分辨率等,可以参考官方文档:https://selenium-python.readthedocs.io/api.html

# 创建 Edge WebDriver
driver = webdriver.Edge(executable_path=edge_driver_path, options=options)

相关推荐

  1. selenium启用MS Edge浏览器/下载MS Edge WebDriver

    2024-03-11 09:46:03       44 阅读
  2. 浏览器文件下载

    2024-03-11 09:46:03       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-11 09:46:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-11 09:46:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-11 09:46:03       87 阅读
  4. Python语言-面向对象

    2024-03-11 09:46:03       96 阅读

热门阅读

  1. 嵌入式开发的3种架构

    2024-03-11 09:46:03       46 阅读
  2. 大数据开发(Spark面试真题-卷四)

    2024-03-11 09:46:03       47 阅读
  3. 新概念英语第二册 (75)

    2024-03-11 09:46:03       35 阅读
  4. sql高级

    sql高级

    2024-03-11 09:46:03      43 阅读
  5. 【力扣hot100】刷题笔记Day24

    2024-03-11 09:46:03       46 阅读
  6. git 不同远程仓库合并

    2024-03-11 09:46:03       42 阅读
  7. openmesh 学习笔记

    2024-03-11 09:46:03       63 阅读