selenium不打开浏览器进行自动化操作

1.配置selenium环境,地址:
https://blog.csdn.net/liaoqingjian/article/details/116785445?spm=1001.2014.3001.5502

2.下载selenium库:pip install selenium

3.代码示例:

from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_argument("headless")
driver = webdriver.Chrome(chrome_options=option)
# driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
print(driver.title)
driver.maximize_window()  # 窗口最大化
# 定位输入框
input_tag = driver.find_element_by_id('kw')
# 模拟键盘输入关键字
input_tag.send_keys("妹子图")
# 键盘操作
input_tag.send_keys(Keys.ENTER)
driver.quit()

你可能感兴趣的:(笔记,selenium,python)