使用selenium登录12306

from selenium.webdriver import Chrome
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")
posted @ 2022-11-05 20:29  guorunbin  阅读(47)  评论(0编辑  收藏  举报