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