from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.common.by import By
# 设置Edge浏览器的选项
edge_options = EdgeOptions()
edge_options.add_argument('--ignore-certificate-errors') # 忽略证书错误
edge_options.add_argument('--start-maximized') # 浏览器最大化启动
# 指定Microsoft Edge WebDriver的路径
service = EdgeService(executable_path='path_to_msedgedriver')
# 创建WebDriver对象,使用Edge浏览器
driver = webdriver.Edge(service=service, options=edge_options)
# 打开指定网页
driver.get('https://www.example.com')
# 查找页面元素并进行操作
try:
element = driver.find_element(By.ID, 'element_id')
print(f"Element found: {element.text}")
except Exception as e:
print(f"Element not found: {e}")
# 关闭浏览器
driver.quit()
selenium库中的相关模块。EdgeOptions()类设置浏览器启动时的一些参数,如忽略证书错误和启动时最大化窗口。EdgeService指定Microsoft Edge WebDriver(即msedgedriver)的路径。get方法打开指定的URL。find_element方法查找页面上的元素,并对其进行操作(如打印文本内容)。quit方法关闭浏览器。上一篇:endswith函数python
下一篇:python字符串处理
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站