12306 check in advance for Beijing to Changchun Spring Festival train Tickets

Source: Internet
Author: User

12306 on the day too far away from the train can not be found, but the interface is actually able to return, but the front limit is not allowed to check.

By clicking the Query button to grab the packet (F12 network can grab the packet, you can also grab the package tool), you can get to the query interface and upstream parameters. By simulating the request, replacing the specified upstream parameters with the data returned by the parsing interface, you can get all the matching requirements for the specified day home, the Python code is as follows (the following code replaces only the Querydate parameter values in the URL upstream parameter, from_station and To_ Station parameter values can also be captured to replace the package):

#-*-coding:utf-8-*-ImportRequests,json#Enter parameter date format:yyyy-mm-dddefquery_tickets (date): s=requests. Session () URL="https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate="+date+"&from_station=bjp&to_station=cct"R= S.get (url,verify=False) Json_r=json.loads (r.content) Date=" ". Join (json_r["Data"]["searchdate"].split ("  "))     forTicketinchjson_r["Data"]["datas"]: Start_station_name= ticket["From_station_name"] End_station_name= ticket["To_station_name"] Train_no= ticket["Train_no"] Short_train_no= ticket["Train_no"][0:len (ticket["Train_no"])-2]         forOneinchShort_train_no:ifone.isupper (): Index=Short_train_no.index (one) train_no=Short_train_no[index:len (short_train_no)] Start_time= ticket["start_time"] Arrive_time= ticket["Arrive_time"]        PrintStart_station_name+u"to the"+end_station_name+" "+train_no+" "+date+" "+start_time+" "+Arrive_timeif __name__=='__main__': Query_tickets ("2017-01-25")

The arguments passed in the Query_tickets method in the script are unique to the date (from Beijing, the destination Changchun, the ticket type is the adult ticket three the upstream parameter value has been written dead in the GET request URL, can actually catch the package to replace it). The above code takes January 25 as an example, running the script effect as follows:

Just a way of thinking, don't take it too seriously. The actual Rob I have downloaded the NetEase train ticket this app, according to the results of the above query now select the number of trips to rob, and then in the NetEase train ticket this app set up a targeted robbery ticket scheme, the success rate should be greater. This is my plan to rob the ticket this year.

12306 check in advance for Beijing to Changchun Spring Festival train Tickets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.