写Selenium WebDriver的Python代码用于在Web页面中查找一个元素并点击它用ByXPATH指定查找元素的方式为XPath路径在Web页面中查找到下一页元素并点击下一页按钮html是这样:div data-testid=pagination class=a826ba81c4 fa71cba65b fa2f36ad22 afd256fc79 d08f526e0d ed11e24d0
from selenium import webdriver from selenium.webdriver.common.by import By
创建浏览器实例
driver = webdriver.Chrome()
打开网页
driver.get("https://example.com")
通过XPath路径查找元素
element = driver.find_element(By.XPATH, "//div[@class='f32a99c8d1 f78c3700d2']/button[@aria-label='下一页']")
点击元素
element.click()
关闭浏览器
driver.quit()
原文地址: http://www.cveoy.top/t/topic/ewwL 著作权归作者所有。请勿转载和采集!