1.下载python和Selenium。
2.创建ticket.py文件
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
import time
driver = webdriver.Firefox()
driver.get("https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E5%B9%BF%E5%B7%9E,GZQ&ts=%E9%95%BF%E6%98%A5,CCT&date=2020-12-15&flag=N,N,Y")
ele=driver.find_elements_by_class_name("btn72")[0].is_displayed()
# print(ele)
def my_abs(n):
if n:
WebDriverWait(driver, 10).until(lambda x: x.find_elements_by_class_name("btn72")[0]).click()
else:
time.sleep(0.5)
driver.refresh()
my_abs(n)
my_abs(ele)
WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("djPassenger_0")).click()
WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("submitOrder_id")).click()
3.点击运行即可,driver.get的链接要根据实际情况复制粘贴,登录的逻辑要手动进行认证。
网友评论