GouHuang

导航

 

chrome驱动下载:http://chromedriver.storage.googleapis.com/index.html

注意:要根据自己浏览器版本去下载chrome驱动程序(右上 -> 帮助 -> 关于Google Chrome ,查看chrome版本信息)

下载库:pip install selenium

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions
from selenium.webdriver.chrome.service import Service

# 防止selenium 被检测
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 浏览器驱动路径
service_path = Service('./chromedriver.exe')
# 实例化浏览器对象
driver = webdriver.Chrome(service=service_path, options=option)
# 访问 百度
driver.get('https://www.baidu.com')
# 浏览器窗口最大化
driver.maximize_window()
# 获取id为 kw 的标签,并填入 '自动化测试'
driver.find_element(By.ID, 'kw').send_keys('自动化测试')
# 获取id为 su 的标签,并点击
driver.find_element(By.ID, 'su').click()

# 关闭浏览器
driver.quit()
posted on 2022-07-18 16:43  GouHuang  阅读(432)  评论(0编辑  收藏  举报