from selenium.webdriver import Chrome标签:web,登录,webdriver,selenium,html,12306,import,div From: https://www.cnblogs.com/guorunbin/p/16861021.html
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
import time
option=Options()
option.add_argument('--disable-blink-features=AutomationControlled')
#躲过浏览器控件的检测
web=Chrome(options=option)
web.get("https://kyfw.12306.cn/otn/resources/login.html")
web.find_element(By.XPATH,"/html/body/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/input").send_keys("12345678")
#输入账号密码
web.find_element(By.XPATH,"/html/body/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/input").send_keys("12345678")
web.find_element(By.XPATH,"/html/body/div[1]/div[2]/div[2]/div[1]/div[1]/div[4]/a").click()
time.sleep(5)
btn=web.find_element(By.XPATH,"/html/body/div[1]/div[4]/div[2]/div[2]/div/div/div[2]/div/div[1]/div[2]/span")
#定位到滑动条
ActionChains(web).drag_and_drop_by_offset(btn,300,0).perform()
input("wait")