Python implements the 12306 train ticket queryer and python12306 queryer

Source: Internet
Author: User
Tags virtualenv

Python implements the 12306 train ticket queryer and python12306 queryer

12306 train ticket purchasing software has been used by everyone. How to Use Python to write a command line train ticket viewer and require you to run a command line on the command line to obtain the desired train ticket information? Let's take a look at this article.

Python train ticket queryer

Interface settings

Let's give a name to this small application first. Since it is used to query ticket information, it is called tickets.

We hope that users can get the desired information as long as they enter the origin site, arrival site, and date. Therefore, tickets should be used as follows:

$ tickets from to date

Final $ tickets [-gdtkz] from to date

Development Environment

Use virtualenv to create a virtual environment, and use Python3 for development,

$ virtualenv -p /usr/bin/python3 venv

Run the following command to activate it:

$ . venv/bin/activate

Resolution Parameters

Python has many tools for writing command line applications. We use docopt, a simple and easy-to-use tool. We should install it first:

$ pip3 install docopt

Docopt can parse parameters according to the format defined in the document string,

Get Data

Https://kyfw.12306.cn/otn/lcxxcx/query? Purpose_codes = ADULT & queryDate = 2016-07-01 & from_station = SHH & to_station = BJP

Https://kyfw.12306.cn/otn/resources/js/framework/station_name.js? Station_version = 1.8955

Save stations.html

Display result

The prettytable database allows us to format and display data like the MySQL database.

$ pip3 install prettytable


The above section describes how to implement the 12306 Train Ticket finder in python. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

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.