1.导入相关库
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.chrome.service import Service
2.指定【chromedriver.exe】得路径。
# 设置驱动路径
path = Service(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
3.调用网页。
# 设置驱动路径
path = Service(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
# 设置options参数
option = webdriver.ChromeOptions()
# 浏览器不提供可视化界面
option.add_argument('--headless')
# 隐藏正受到自动测试软件的控制
option.add_experimental_option("excludeSwitches", ["enable-automation"])
# 指定浏览器分辨率
option.add_argument('window-size=1920x1080')
# 最大化运行/全屏窗口
# option.add\_argument('--start-maximized')
driver = webdriver.Chrome(service=path, options=option)
driver.get("https://www.baidu.com")
print(driver.title)
driver.find_element(By.ID,"kw").send_k