Python3.6 realizes 12306 train ticket automatic Rob ticket, attach source code

Source: Internet
Author: User
Tags garbage collection ticket

Python (pronunciation: English [? Pa?θ?n], beauty [? Pa?θɑ:n]), is an object-oriented, literal translation of computer programming language, but also a powerful general-purpose language, has nearly 20 years of development history, mature and stable. It contains a comprehensive set of standard libraries that are easy to understand and can easily accomplish many common tasks. Its syntax is very simple and clear, unlike most other programming languages, it uses indentation to define the statement.

Python supports imperative programming, object-oriented programming, functional programming, slice-oriented programming, generic programming, and many programming paradigms. Like scheme, Ruby, Perl, Tcl and other dynamic languages, Python has garbage collection and can automatically manage storage usage. It is often used as a scripting language to handle system administration tasks and network programming, but it is also well suited to perform high-level tasks. The Python virtual machine itself can run on almost all operating systems. Using tools such as Py2exe, PyPy, Pyinstaller, you can convert Python source code into a program that can run out of the Python interpreter.


Recently learning Python, so with Python wrote this 12306 Rob ticket script, share out, and everyone to communicate and learn, there is wrong place, please make a lot of corrections. Words not much to say, into the topic:

This script can only be used to brush one bus at present, the number of people may be multiple, support selection as a type.

Implementation of the idea is Splinter.browser simulation browser login and operation, because 12306 of the verification code is not automatic identification, so, the verification code needs to be manually identified by the user, and the login operation, after the thing, the script to operate on it, here are some of my test time:

First step: For example, first enter the basic information to rob the ticket


The second step: then enter the login page, you need to manually enter the verification code, and click the login operation


The third step: After landing, automatically enter into the ticket page, such as this


Finally: just wait and see the results of the ticket, such as, say is the brush ticket success, brush to the ticket, will be text messages and mail notice, please remember to go to 12306 in time to pay, or white rob.


Python Runtime Environment: python3.6

Modules used: RE, splinter, time, SYS, HTTPLIB2, urllib, smtplib, email

Modules that are not installed, use PIP instatll for installation, for example: Pip install splinter

The following code is the introduction of all the modules used in this script:


Pre-swipe information preparation, I mainly say the start and destination of the cookie value to obtain, because when entering the city, the need to pass the cookie value, the cookie value can pass 12306 official website, Then in the F12 (believe all the coder know this bar) inside the network query request cookie can be seen, in the header of the request can be found, _jc_save_fromstation value is the departure station Cookie,_jc_save_ The value of tostation is the cookie of the destination, which is then added to the city's Cookie dictionary city_list in the code, the key is the city's first letter, and the value is the form of the cookie value.

Rob ticket, definitely need to log in first, I am here to simulate the login operation, will automatically populate the 12306 account name and password, of course, you can also open the browser to modify the account and password, the implementation of the key code is as follows:


After login, is to control the various operation of the ticket processing, here, I do not paste code, because the code is more, do not worry, in the end, I will post the complete code.


When the ticket is successful, I will be the double notification of text message and mail, of course, here, the platform for SMS notification, you use that specific to modify the code, I use each other million wireless experience version of the free SMS notification interface; Send mail module I use Smtplib, send mail server with 163 mailbox, If you use 163 mailbox, you have not set the client authorization password, remember to set the client authorization password first, very convenient. The following are the main implementation codes:


Said so much, feel is said a lot of nonsense ah, haha, sorry, delay everyone time to see me, I put on the most concerned about the source code, please connect code, everyone in the attempt to run the process, there are any problems, you can give me a message or private messages I, I see will promptly reply to you:









What can python do?

Web development and crawler are more suitable for the 0 foundation

Automated operation and maintenance development and automated testing are suitable for those who are already doing operations and testing

Big Data data analysis This aspect is very need professional professional of relatively strong

Scientific calculations are generally used by researchers

Machine learning and AI first degree requirements high next high number requirements high difficulty is very big

I have a public number, and I often share some of the stuff about Python technology. If you like my share, you can use the search "Python language learning" to follow

Welcome to join thousands of people to exchange questions and answers skirt: 588+090+942


Python3.6 realizes 12306 train ticket automatic Rob ticket, attach source code

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.