2022年 11月 3日

python实现模拟浏览器操作

from selenium import webdriver
# 需要先安装谷歌驱动(http://chromedriver.storage.googleapis.com/index.html)安装你谷歌浏览器对应的版本,放在python安装目录下,不然会报错:找不到驱动
opt = webdriver.ChromeOptions()
# opt.add_argument('headless')  # 设置option,后台运行
driver = webdriver.Chrome(options=opt)   # 创建浏览器对象

driver.get('http://localhost:1276/Login.aspx')  # 打开网页
driver.find_element(by = "id", value="kw").send_keys("疫情")
driver.find_element(by = "id", value="su").click()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9