lihu5841314 发表于 2021-6-5 16:16

selenium 学习笔记03

from selenium importwebdriver
import time
from selenium.webdriver.chrome.options importOptions   #无头导入设置
"""
# 无头浏览器
chrome_options = Options
# 增加无头
chrome_options.add_argument('--headless')
chrome_options.add_argement("--disable-gpu")
# 防止被网站识别
chrome_options.add_experimental_option('excludeSwitches',['enable_automation'])
browser = webdriver.Chrome(chrome_options=chrome_options)
"""



url ="https://www.douban.com/"
driver =webdriver.Chrome()
driver.get(url)
time.sleep(2)
rep1 = driver.find_element_by_xpath('//*[@id="anony-sns"]/div/div/div/div/ul/li/div/a')#获取电影标签

rep2 = driver.execute_script("arguments.click();",rep1)                     #点击


#页面的回退
time.sleep(1)
driver.back()
#页面的前进
time.sleep(1)
driver.forward()
页: [1]
查看完整版本: selenium 学习笔记03