Python action 12306 Grab ticket script

Source: Internet
Author: User
Tags windows x86 ticket

There is no use of Python for some time, a few days ago, a friend brought up a piece about the use of Python to rob the train ticket article, Baidu to achieve the technical details of the train ticket, online but there is a lot of information, is not fresh things. In the understanding of some technical means, read some of the Great God's blog post, also tried to achieve a bit, the code is coarse, pure when entertainment, this article in the Windows system to complete. It is necessary to mention that the verification code part of the ticket process can only be done manually.

First, the tools and components I need are:

    • Chrome browser
    • Browser driver Chromedriver
    • Python 3.5
    • Web Application Test Tool splinter

Chrome browser can be downloaded by itself, and its browser driver Chromedriver can be found at the following link: http://chromedriver.storage.googleapis.com/index.html?path=2.20/

Download Python on the official website, choose Windows x86 executable installer, install the idle, Pip and so on together, tick the option to add Python as environment variable (run python under Windows cmd, Environment variables need to be set). After the installation is complete, execute: Pip install splinter install splinter.

The basic configuration is complete, test it, run Python under CMD, and type the following instructions, respectively:

At this point, you may encounter some situations.

Chromedriver.exe processes are often closed

Workaround: Chrome version 1th 52.XX. XX can then go and find the corresponding version of the Chromedriver

    • 1. Download Chromedriver driver package (: http://chromedriver.storage.googleapis.com/index.htmlpath=2.7/)
      Note Read Note.txt Download the same version of the driver package that you use for your browser.

There are problems with environment variables here you can directly copy the Chromedriver.exe to the Python installation directory Scripts a copy and C:\Windows\System32 the next copy.

Pro-Test

Try the code above and test it.

Attach GitHub code Https://github.com/stay-youbg/python12306.git

The cookie value here can be opened by pressing F12 Click to view the cookie

Python action 12306 Grab ticket script

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.