because the tickets are difficult to grab, sometimes the tickets need to be sold out, and we need to collect the leak, so we can use this script.

is implemented, automatically query the number of tickets of a ticket, when the number of changes, will automatically send QQ mail to the mailbox for reminding.

, some of the details of sending mailboxes can refer to my previous blog: Python sending mail (SMTP) QQ mailbox

scripts using Python + selenium + exception. When the

is used, you need to change the

mailbox information in the code, the departure station, the arrival station, the train times, the date, and the HTML id:

of the corresponding ticket in the corresponding query page. The developer mode is popped out in the corresponding query page, and the button, then click the corresponding ticket box,   , copy the corresponding ID number to the code in the corresponding.

code as follows:

 #coding:utf8 from selenium import webdriver from selenium.webdriver.common.keys import. ='G14'train_date ='2018-02-14' ZYid ='ZY_5l00000G1441'ZYid ='ZE_5l00000G1441' WZid ='ZE_5l00000G1441'WZid ='WZ_5l00000G1441' def send_email. "Email_to =" 654321@qq.com "hostname =" smtp.qq.com "login =" 123456@qq.com "password =" xddflwjfkkfkbidf "subject =" train_tickets "text = (date:%s) Mtp.login (login, password) MSG = MIMEText (text, "plain", "UTF-8") msg["Subject") = Header (subject, "Subject") N/otn/index/init') elem = driver.find_element_by_id ("fromStationText") elem.clear () elem.send_keys (from_station) elem.send_keys (Keys.ENTER) elem.send_keys (Keys.ENTER) write to the starting station elem = driver.find_element_by_id ("toStationText") Station JS = "document.getElementById ('train_date').RemoveAttribute ('readonly')" remove date hurdles read-only properties driver.execute_script (JS) elem=driver.find_element_by_id ("train_date") elem.clear () elem.send_keys (train_date). Select one way elem.click () elem=driver.find_element_by_id () elem.click () elem=driver.find_element_by_id ("a_search_ticket") begin to query try: elem.click () except Exception: time.sleep () query_times = 0 onetickets_last = 0 twotickets_last = = 0 wztickets_last = 0 1 (1): 1 = "" "" try: driver.find_element_by_id ("query_ticket").Click ().Click () according to the query key can be found to determine the page display correctly or not except Exception: driver.refresh () time.sleep (5); print ("bug"); continue print ("third query:"%) dialectical = = = = Driver.find_element_by_id (ZYid).Text except Exception: driver.refresh () time.sleep (5); print ("bug") continue if not. If (text = = "have" or text = = "no"): onetickets_now = text print ("%s first seat:%s"% (train_num, onetickets_now)) if. Onetickets_now = text print ("%s one seat surplus ticket number:%s"% (train_num, onetickets_now)) if (onetickets_now! = onetickets_last): onetickets_last = onetickets_now. (ZEid).Text query two equal seat remaining ticket if (text = = "have" or text = = "no"): twotickets_now = text print ("%s two equal seat:%s") Ets_last, wztickets_last) else: twotickets_now = text print ("the number of remaining seats in the%s two,%s"% (train_num, twotickets_now)) if (twotickets_now! = = _last) text = driver.find_element_by_id (WZid).Text query if (text = = "have" or text = = "no"): wztickets_now = text print. N_num, onetickets_last, twotickets_last, wztickets_last) else: wztickets_now = text print ("%s free seat number:%s"% (train_num, wztickets_now)) Ast, wztickets_last) print ("") 

above is the whole content of this article, I hope to help everyone's learning, and also hope that a lot of people support the script home.

you may be interested in the article:


This concludes the body part

This paper fixed link:http://www.script-home.com/python-automatically-queries-more-than-12306-tickets-and-sends-mailbox-reminder-scripts.html | Script Home | +Copy Link

Article reprint please specify:Python automatically queries more than 12306 tickets and sends mailbox reminder scripts. | Script Home

You may also be interested in these articles!