使用Selenium和Python编写一个示范的Chrome浏览器脚本示例:

from selenium import webdriver

# 设置Chrome浏览器的路径
chrome_path = "/path/to/chromedriver"

# 创建一个Chrome浏览器实例
driver = webdriver.Chrome(chrome_path)

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

# 查找并输入文本框
search_box = driver.find_element_by_id("search-box")
search_box.send_keys("Hello, World!")

# 提交表单
submit_button = driver.find_element_by_id("submit-button")
submit_button.click()

# 等待页面加载完成
driver.implicitly_wait(10)

# 获取结果
result = driver.find_element_by_id("result").text
print(result)

# 关闭浏览器
driver.quit()

请确保已经安装了Selenium库,并且根据您的系统配置正确设置了Chrome浏览器的路径(chrome_path)。这个示例使用了一个假设的网页,您可以根据实际情况将其替换为您需要操作的网页

chrome用selenium写一个示范python

原文地址: https://www.cveoy.top/t/topic/ie29 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录