Spring Festival is coming , It's time to rush home again ！
stay Github There are also many excellent developers open source based on Python The ticket grabbing project of , For example, it's always hot
12306/py12306, At present, it has accumulated more than 40k Star！
But if you try to use , It will be found that due to 12306 Of Captcha mechanism upgrade , These two projects are The login modules are all down , It's probably not available since last October .
but Don't panic , After some exploration , I've found a ticket grabbing project that works perfectly , And contact the developers @ What about the tea in the jar , come to know Just change some interface addresses of login module , And adjust the acquisition logic of some parameters , You can revitalize Python Ticket grabbing project 12306, The address is as follows
This article will be based on the project Detailed guidance on how to use it quickly Python Grab tickets , Go home smoothly ！
Before we start, we need to understand the whole The idea of grabbing tickets
Before running this project, you need to transfer your Python Upgrade to Python3.6 Or higher , I am a Python3.8 No problem .
First use git Pull down the original project code
git clone https://github.com/gzldc/12306.git
Or download the compressed package and unzip it
The unzipped directory should be as follows
Then start the terminal / Command line ( Mac/Win ), and cd Enter project directory , Execute the following code to install the dependency
pip install -r requirements.txt
It should be noted that , If the download speed is too slow, you can switch the source to solve it , It's the fastest way to use alicloud image for personal testing
This article is not about installing various libraries , All in all
requirements.txt in Dependency libraries must be installed correctly , If there are any installation problems , Please Baidu
We talked about ,GitHub Number one, number two 12306 The reason why the ticket grabbing project is dead is that Login verification code cannot be processed On , But the project we are using now is not to use a user name and password to manage the account , Just when you log in Withdraw relevant information from your account cookie Field that will do , You can follow the steps below .
Start by opening 12306 Official website , Go to the login page and press F12, And select
Then enter the account password verification code and click login , After clicking on
As indicated above , find
uamauthclient The packet goes in and clicks
Cookies, Then follow the instructions in the figure below to record
RAIL_DEVICEID Of three fields value, Copy it and save it , It will be used later
Here we get it 12306 Key information to verify our identity , Let's move on .
Now back to the project catalog , Open the
TickerConfig.py To configure , There are many fields in it. You can check the description and configuration by yourself , This article only introduces some key fields
First you need to modify 53-55 The three variable values of the row , Replace it with the one we just saved
RAIL_DEVICEID Of three fields value, This step is very important , Because there is no need to enter the account and password to use this project , Order by these three parameters
Then modify the passengers as shown in the figure below 、 Train number 、 Travel date and other related information , Fill in this part by yourself , Not much to explain
Here we can use it directly , Of course, you can continue to follow this template file to CDN Speed up 、 agent ip、 Adjust the ticket grabbing mode and other settings , Finally, save and exit
Finally, let's start the project and grab tickets , Back to the terminal / Command line
Execute the following code to open CDN Speed up
python3 run.py c
Then hang it backstage , Reopen a terminal / Command line and go to the project directory , Execute the following code and start to grab tickets
python3 run.py r
As shown in the figure above , If there is no accident, it will output a lot of logs , I chose the ticket from Hangzhou to Wuhu , Because there are more tickets , So I didn't enter the ticket grabbing mode , Just order to be paid
go back to 12306, Click on my order and find a ticket lying there waiting to be paid , All functions from login to order can be used normally ！
Because of time , I didn't test it further in ticket grabbing mode , After communicating with the project author and some of the group friends , A few more points are convenient for you to use
python3 run.py r
This article is from WeChat official account. - AirPython（AirPython）
The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the email@example.com Delete .
Original publication time ： 2021-01-10
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .