当前位置:网站首页>12306 ticket grabbing tutorial

12306 ticket grabbing tutorial

2022-06-22 13:38:00 A hundred years of literature have been written on the left sid


This tutorial is testerSunshine Open source project tutorial , The project code website is https://github.com/testerSunshine/12306

preparation

install python, Proposed installation python3, The version number is 3.6 - 3.7.4 Within the scope of

First step Download the project source code

stay https://github.com/testerSunshine/12306 Download source code in , If the download speed is slow , You can link on the network disk https://pan.baidu.com/s/1fuLGcJ7Yl80eXU_8wfO_iQ Download
Decompress the package after downloading , If available D Under the plate

The second step Screening CDN

Use WIN+R Input cmd Open the command line page , Use cd Command to switch to the compressed folder , This article puts the compressed package into D disc , Switch to D disc , And on again 12306-master Folder . Put in different positions , The operation here is different . then , Use python run.py c Conduct CDN Screening , Due to python Differences in naming , The operation here will be slightly different .
 Insert picture description here

The third step Download dependency Library

When the previous step is completed , Use pip install -r requirements.txt To download some required libraries , Due to pip Differences in naming , The operation here will be slightly different .
 Insert picture description here

Step four Fill in the train ticket information

Find the extracted folder , Find... In it TickerConfig.py file

Fill in the date of arrival

In the 10 Go to the first place 13 That's ok , Fill in the date of arrival , You can fill in more than one

Fill in the departure city

In the 21 That's ok , Fill in the departure city

Fill in the arrival city

In the 24 That's ok , Fill in the arrival city
 Insert picture description here

Fill seats

In the 36 That's ok , Fill seats , You can fill in more than one

Fill in passengers

In the 45 That's ok , Fill in passengers , You can fill in more than one . Be careful : The passengers filled in should be in the common contacts of the account number entered below , If the common contacts are set as students, they will buy student tickets , If it is set as an adult, you can buy an adult ticket

Fill in the account password

In the 48 Row sum 49 That's ok , Insert in 12306 Account and password of the platform

Select local coding

In the 59 That's ok , Set to 2, Perform local coding , Faster
 Insert picture description here

download chrome drive

In the 120 That's ok , take COOKIE_TYPE Set to 1
stay https://www.google.cn/intl/zh-CN/chrome/ download Chrome browser
stay http://chromedriver.storage.googleapis.com/index.html Download and download Chrome The driver corresponding to the browser version ( As long as the large version matches )
Unzip the downloaded file package , In the 123 Line fill in the address , This article will chromedriver.exe Put it in D Under the plate , So it's R"D:\chromedriver.exe"
 Insert picture description here

Set the sender and recipient of email alerts ( Not set up )

If you do not want to set ,83 On the way True Change it to False
In the 82 Row to 89 That's ok , Set the sender's mailbox in turn 、 Recipient email 、 Sender email account 、 Sender's email password 、 Sender email host, Note that if the sender mailbox is set to qq mailbox , Then the sender's email password should be the authorization code , From the mailbox –> Account –> Turn on smtp Get the authorization code from the service .

Set wechat reminder ( Not set up )

If you do not want to set ,93 On the way True Change it to False
In the 92 Row to 95 That's ok , Get into http://sc.ftqq.com/3.version, Follow the page prompts to get secret
 Insert picture description here
 Insert picture description here

Step five Start grabbing tickets

Enter... On the command line python run.py r Start grabbing tickets
 Insert picture description here
The following text appears on the command line

 At the 355 Queries    Date of ride : 2018-02-12   Train number G4741,G2365,G1371,G1377,G1329  Check no tickets    Agent settings   nothing    Total time 429ms
 Train number : G4741  Departure station :  Shanghai   The terminal :  Shaoyang   Second-class seat : Yes 
 Trying to submit a reservation ...
 Try to submit an order ...
 The ticket was successful 
 Queue succeeded ,  There are still some tickets left : 359  Zhang 
 Using auto identification captcha function 
 The verification code passed , Submitting order 
 Order submitted successfully !
 Waiting time is expected to be left  -12 ms
 Waiting time is expected to be left  -6 ms
 Waiting time is expected to be left  -7 ms
 Waiting time is expected to be left  -4 ms
 Waiting time is expected to be left  -4 ms
 Congratulations on your successful booking , Order No :EB52743573,  Please open your browser and log in now 12306, visit ‘ Outstanding orders ’, stay 30 Pay in minutes !

It means that the ticket grabbing is successful , Log in 12306 Visit the outstanding order to complete the payment ~

common problem

How to choose student tickets

stay 12306 Of your favorite contacts , If the contact is set as a student , Then buy student tickets , Set to adult , Buy adult tickets

Example TickerConfig.py Configuration of

# -*- coding=utf-8 -*-
#  About the configuration of the software , Be sure to look at it. !!!
# ps:  If it's a standby ticket , Users who need to pass the verification of human identity and activated “ The railway goes smoothly ” Members can submit alternate requests , Please follow the operating instructions on the railway 12306app. On the completion of human verification 
#  The question about whether we can continue to pick up the leakage after waiting is explained here :  The software is full-automatic standby plus leak detection , If the software backup succeeds, it will stop robbing tickets , Send an email notice , But it will not affect you to continue to pick up the leak ,
#  If I pick up the leak at this time , It can also be paid successfully , in other words , Leak collection + be an alternate , It can maximize the success rate of ticket grabbing 

#  Swipe ticket mode :1= Brush ticket  2= be an alternate + Brush ticket 
TICKET_TYPE = 1

#  Departure date (list) "2018-01-06", "2018-01-07"
STATION_DATES = [
    "2018-01-06", "2018-01-07"
]

#  Fill in the number of cars you need to buy (list),"G1353"
#  Change the car number to fill in the rules , notes :( The previously set train number logic does not change ), If the train number is blank , That is, all the train times of the day are included in the screening and return 
#  Not filling in the train number is the whole thing list It's only when it's empty , If it's not empty , Still judge the train number , This is the wrong way to write  [""],  Correct writing  []
STATION_TRAINS = ["G7031", "G7037"]

#  Departure city , For example, Shenzhen North , Just fill in Shenzhen and you'll find 
FROM_STATION = " Nanjing South "

#  Get to the city   For example, Shenzhen North , Just fill in Shenzhen and you'll find 
TO_STATION = " Shanghai "

#  seat (list)  Multiple seats ex:
# " Business block ",
# " First class seat ",
# " Second-class seat ",
# " First class ",
# " Soft sleeper ",
# " Hard sleeper ",
# " Hard seat ",
# " No seat ",
# " Move and lie ",
SET_TYPE = [" First class seat ", " Second-class seat "]

#  When the remaining tickets are smaller than the passengers , If you choose to submit first , Then delete the contact person and the remaining votes in the same submission 
# bool
IS_MORE_TICKET = True

#  Passengers (list)  Multiple passengers ex:
# " Zhang San ",
# " Li Si "
TICKET_PEOPLES = [" Zhang San ", " Li Si "]

# 12306 Login account 
USER = "admin"
PWD = "admin"

#  The default time to join the black house is 5 minute , This function is to prevent zombie tickets from failing to place orders and missing normal tickets 
TICKET_BLACK_LIST_TIME = 5

#  Automatic code generation 
IS_AUTO_CODE = True

#  Set up 2 Local automatic coding , Need configuration tensorflow and keras library ,3 Code the clouds , Due to the limited resources of cloud code server ( by 2h4C Of cpu The server ), Please do not maliciously request , Otherwise, you can only shut down the server 
# ps:  Please don't rely on cloud server resources all the time , Thank you to all the students who provide the server 
AUTO_CODE_TYPE = 2

#  Set the address of cloud code server here , If there is a self built server , You can change 
HOST = "120.77.154.140:8000"
REQ_URL = "/verify/base64/"
HTTP_TYPE = "http"
# HOST="12306.yinaoxiong.cn" # The standby server is not stable 
# REQ_URL="/verify/base64/"
# HTTP_TYPE="https"

#  Mailbox configuration , If the ticket snatch is successful , Will notify you via mail configuration 
#  list 163
# email: "[email protected]"
# notice_email_list: "[email protected]"
# username: "xxxxx"
# password: "xxxxx
# host: "smtp.163.com"
#  list qq ,qq The settings are complicated , Need to be in the mailbox --> Account --> Turn on smtp service , Get authorization code == Email login password 
# email: "[email protected]"
# notice_email_list: "[email protected]"
# username: "xxxxx"
# password: " Authorization code "
# host: "smtp.qq.com"
EMAIL_CONF = {
    
    "IS_MAIL": True,
    "email": " Sender email ",
    "notice_email_list": " Recipient email ",
    "username": " Sender email account ",
    "password": " Sender's email password ",
    "host": " mailbox host Such as smtp.163.com",
}

#  Open or not  server sauce   Wechat reminder ,  You need to go to  http://sc.ftqq.com/3.version  Scan code binding to get  SECRET  And concerned about the official account for the announcement of the results of the robbing 
SERVER_CHAN_CONF = {
    
    "is_server_chan": True,
    "secret": " Acquired secret"
}

#  Open or not cdn Inquire about , Can test tickets faster  1 For opening ,2 To close 
IS_CDN = 1

#  There are two kinds of single interface ,1  Automatic search and order of simulated web page ( unstable ),2  The ticket button at the back of the simulated train number places an order ( Steady as an old dog )
ORDER_TYPE = 2

#  Order mode  1  For presale , Refresh at the same time , Refresh interval 0.1-0.5S,  Then it will check the time , such as 12 Order presale , The script will be in 12.00 Check in , Refresh order 
# 2  It's a leak , The refresh interval for leakage detection is 0.5-3 second , The time interval is long , It's not easy to seal ip
ORDER_MODEL = 1

#  Whether to open the agent , 0 On behalf of closed , 1 To begin 
#  Please make sure that the agent ip Is it available , Fully tested in the test box , Turn on this function again , Otherwise, it may delay your precious time of ticket purchase 
#  Usage method :
# 1、 stay agency/proxy_list Fill in the list of agents ip
# 2、 test UnitTest/TestAll/testProxy  Test whether the agent can use 
# 3、 Open agent ip
IS_PROXY = 0

#  Booking time ,  If it's leak detection mode , This operation can be ignored 
OPEN_TIME = "12:59:57"
# 1= Use selenium obtain devicesID
# 2= Use the web side /otn/HttpZF/logdevice obtain devicesId, The algorithm of this interface may have some problems at present , If login always 302 Please change the configuration to 1
# 3= Open your own browser in headers-Cookies To grab RAIL_DEVICEID and RAIL_EXPIRATION, This one doesn't have to be configured selenium
COOKIE_TYPE = 1
#  If COOKIE_TYPE=1, You need to configure chromeDriver route , Download address http://chromedriver.storage.googleapis.com/index.html
# chromedriver Configuration version only and chrome The big version match of 
CHROME_PATH = R"D:\chromedriver.exe"

#  in order to docker37  Prepared environment variables ,windows The environment can ignore this parameter 
CHROME_CHROME_PATH = "/opt/google/chrome/google-chrome"

#  If COOKIE_TYPE=3,  You need to configure RAIL_EXPIRATION、RAIL_DEVICEID Value 
RAIL_EXPIRATION = ""
RAIL_DEVICEID = ""
# RAIL_EXPIRATION = "1577034103293"
# RAIL_DEVICEID = "CDno29Erc_Pf3FSXb4dzq-Op64EhWrsi5yUZKVIKR1MAfYo2qFlCeXD8VkexY7_1qg-ClV-fE8j9jgVlPZxRh3wVc2iqLe_5A8sdr62qZx4B22JPF8lFCjpgTKZ5ODW90HJd5tiQsJ1KR9nOqHRxHj1FT5LEIwfw"


# 1=> For always random ua,2-> Only one time at random when starting ua
RANDOM_AGENT = 2

PASSENGER_TICKER_STR = {
    
    ' First class seat ': 'M',
    ' First class ': 'P',
    ' Second-class seat ': 'O',
    ' Business block ': 9,
    ' Hard seat ': 1,
    ' No seat ': 1,
    ' soft seats ': 2,
    ' Soft sleeper ': 4,
    ' Hard sleeper ': 3,
}

#  Protect 12306 Official website request frequency , Set random request time , The principle is 5 Minutes are not greater than 80 Time 
#  Maximum interval request time 
MAX_TIME = 3
#  Minimum interval request time 
MIN_TIME = 1

#  Software version 
RE_VERSION = "1.2.004"

原网站

版权声明
本文为[A hundred years of literature have been written on the left sid]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221137547164.html