from selenium import webdriver
import time
bro = webdriver.Chrome(executable_path="./chromedriver.exe")
bro.get("https://www.taobao.com/")
# 标签定位
search_input = bro.find_element_by_id("q")
# 标签交互
search_input.send_keys("iphone")
# 执行js程序
bro.execute_script("window.scrollTo(0, 300)")
time.sleep(2)
# 点击搜索按钮
btn = bro.find_element_by_css_selector(".btn-search")
btn.click()
bro.get("https://www.baidu.com")
# 回退
time.sleep(2)
bro.back()
# 前进
time.sleep(2)
bro.forward()
# 关闭浏览器
time.sleep(5)
bro.quit()
使用selenium对浏览器进行基本操作
最新推荐文章于 2022-08-29 23:28:58 发布