Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to get a ticket home

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to use Python to grab a ticket home, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

It is reported that during the Spring Festival travel period this year, the number of passengers sent by railways across the country will increase by 8.0% compared with the same period last year. Reached 440 million person-times.

Railway Spring Festival transportation in 2020 begins on January 10 and ends on February 18 for a total of 40 days, 15 days before and 25 days after the festival. Train tickets for Spring Festival transportation are officially on sale on December 12 this year.

No matter how difficult it is, you still have to get your home back, and you still have to grab tickets, so this week, GitHub programs that use Python to grab tickets are back on the Top list.

This ticket-grabbing assistant was born in 2017 by Wen Xianping / testerSunshine. At present, the project has nearly 20000 stars, so you can imagine how eager programmers are to go home!

The strongest ticket-grabbing assistant in history, following the 12306 update

As you can see from the project's update log, the first update of the project was on May 13, 2017. since then, a total of 32 updates have been made, most of which are by the author himself and supported by some developers.

The project is basically updated with the update of the 12306 website, such as the alternate function added in the Spring Festival travel last year, which paid in advance when the tickets were sold out and automatically made up after others refunded the tickets.

The project also added this feature this year:

At present, this ticket-grabbing assistant basically supports all the major functions of 12306, including email notification, intelligent standby and so on.

This ticket-grabbing assistant can be called the strongest ticket-grabbing assistant in history. The author provides an exchange group at the back of the project. Seven of the nine groups are now full. You can imagine how powerful this is.

Every code, just to grab a ticket home

The author has made a lot of efforts for this project. First of all, let's take a look at the author's ideas:

The train of thought is not complicated and quite compact. First of all, you need to download a machine learning model to automatically identify the 12306 CAPTCHA, and the model needs to be placed in the project root directory.

① model download link:

Https://pan.baidu.com/s/1rS155VjweWVWIJogakechA password: bmlm

Download ② Git Warehouse:

Https://github.com/testerSunshine/12306model.git (1) cd 12306 / (2) git clone https://github.com/testerSunshine/12306model.git

The installation of the model requires some dependencies, as follows:

Once the dependencies are met, you can install them.

Root users (avoid problems in multi-Python environments):

Pip3 install-I https://pypi.tuna.tsinghua.edu.cn/simple-r requirements.txt

Non-root users (avoid using different environments for installation and runtime):

Pip3 install-I https://pypi.tuna.tsinghua.edu.cn/simple-r requirements.txt

If many Windows users are unable to install Tensorflow, it is possible to lower the version or increase the version.

Note that if the dependency in the above list is reported to be missing during the process, you only need to install the corresponding dependency package using pip3 alone.

Then you can start the project.

Step 1: modify the configuration file

# Test whether mailbox and server python are available. The premise of server sauce test is that server sauce switch is enabled # you can configure server sauce reminder (recommended) [configuration tutorial] (whether https://www.jianshu.com/p/8d10b5b9c4e3) # uses python3 or python depends entirely on whether the environment variable configured during installation is python3. The default environment variable for server sauce is server t.

Profile description (read the instructions carefully):

#-*-coding=utf-8-*-# about the software configuration instructions, be sure to read it! # ps: if it is an alternate ticket, users who need to pass the verification of witness consistency and activated "Railway smooth running" members can submit alternate requirements, please follow the operation instructions in the railway 12306app. Complete witness verification # the question of whether you can continue to pick up leaks after the candidate is explained here: the software is a fully automatic candidate to pick up leaks, and if the software candidate succeeds, it will stop grabbing tickets and send e-mail notices, but it will not affect you to continue to pick up leaks. # if you pick up leaks at this time, payment can be successful, that is to say, leak detection + candidate Can maximize the success rate of ticket grabbing # ticket brushing mode: 1 = ticket brushing 2 = alternate + ticket brushing TICKET_TYPE = 1 # departure date (list) "2018-01-06", "2018-01-07" STATION_DATES = ["2020-01-17"] # fill in the number of trains to be purchased (list), "G1353" # modify the train filling rules, note: (the previously set train logic remains unchanged) If the number of trains is filled in blank, then all trips on the same day are included in the screening return # if the number is left empty, the whole list is empty. If it is not empty, the number of trains will still be judged. This is the wrong way to write [] STATION_TRAINS = ["G1120"] # departure city, such as Shenzhen North. If you fill in Shenzhen, you will find FROM_STATION = "Guangzhou" # to a city such as the north of Shenzhen. Fill in Shenzhen and find TO_STATION = "Wuhan" # seats (list) multiple seats ex: # "Business seat", # "first Class seat", # "second Class seat", # "Special Class seat", # "soft berth", # "hard berth", # "hard seat", # "No seat", # "moving berth" SET_TYPE = ["second class"] # when the remaining ticket is less than the passenger If you choose to submit first, the contact person and the remaining votes will be deleted in the submission of # bool IS_MORE_TICKET = True # passengers (list) multiple passengers ex: # "Zhang San", # "Li Si" TICKET_PEOPLES = ["] # 12306 login account USER =" PWD = "# the default time for joining the dark room is 5 minutes. In order to prevent the zombie ticket from being placed all the time without successfully missing the normal ticket TICKET_BLACK_LIST_TIME = 5 # automatic coding IS_AUTO_CODE = True # setting 2 local automatic coding, you need to configure tensorflow and keras libraries, 3 for cloud coding, as the resources of the cloud coding server are limited (2h5C's cpu server), please do not maliciously request Otherwise, you can only shut down the server # ps: please do not rely on the CVM resources all the time. Thank all the students who provide the server here AUTO_CODE_TYPE = 3 # set the cloud code server address here, if there is a self-built server. You can change the mailbox configuration of HOST= "120.77.154.140HTTP_TYPE= 8000" REQ_URL= "/ verify/base64/" HTTP_TYPE= "http" # HOST= "12306.yinaoxiong.cn" # standby server with poor stability # REQ_URL= "/ verify/base64/" # HTTP_TYPE= "https" # if the ticket grab is successful. You will be notified by email configuration # email: "xxx@163.com" # notice_email_list: "123@qq.com" # username: "xxxxx" # password: "xxxxx # host:" smtp.163.com "# enumerate qq. The qq setting is complicated. You need to go to mailbox-> account-- > enable smtp service. Get authorization code = = email login password # email: "xxx@qq.com" # notice_email_list: "123@qq.com" # username: "xxxxx" # password: "authorization code" # host: "smtp.qq.com" EMAIL_CONF = {"IS_MAIL": True, "email": "," notice_email_list ":", "username": "" "password": "," host ":" smtp.qq.com ",} # whether to turn on server paste Wechat reminder Before use, you need to go to http://sc.ftqq.com/3.version scan code binding to obtain SECRET and follow the official account SERVER_CHAN_CONF = {"is_server_chan": False, "secret": ""} # whether to enable cdn query, which can faster detect whether the ticket is enabled. 1 is enabled, and 2 is divided into two types to disable IS_CDN = 1 # to place an order. 1 simulated web page automatically pick up leaks to place orders (unstable), 2 simulated train number behind the purchase button to issue orders (steady as an old dog) ORDER_TYPE = 2 # issuing orders mode 1 is pre-booking, hour refresh, refresh interval 0.1s-0.5s, and then the time will be checked, such as pre-sale at 12:00, then the script will check tickets at 12.00, refresh order # 2 is to pick up leaks The refresh interval for picking up leaks is 0.5-3 seconds, and the time interval is long. It is not easy to seal ip ORDER_MODEL = 1 # whether to enable the agent, 0 means to close it, 1 means to start # Please make sure that the agent ip is available when you turn on this feature, and then enable this function after a full test in the test. Otherwise, it may waste your precious time to buy tickets # usage: # 1. Fill in the agent ip # 2 under the agency/proxy_list list, test whether the UnitTest/TestAll/testProxy test agent can use # 3, turn on the agent ip IS_PROXY = 0 # pre-sale release time, if it is leak detection mode You can ignore this action OPEN_TIME = "12:59:50" # 1 = use selenium to get devicesID # 2 = use web side / otn/HttpZF/logdevice to get devicesId, the algorithm of this interface may have some problems at present, if you log in to 302, please change to configure 1 # 3 = open your browser to grab RAIL_DEVICEID and RAIL_EXPIRATION in headers-Cookies, this does not need to configure selenium COOKIE_TYPE= 3 # if COOKIE_TYPE=1 You need to configure the chromeDriver path to download the address http://chromedriver.storage.googleapis.com/index.html # chromedriver configuration version as long as it matches the large version of chrome CHROME_PATH = "/ usr/src/app/chromedriver" # Environment variables prepared for docker37 The windows environment can ignore this parameter CHROME_CHROME_PATH = "/ opt/google/chrome/google-chrome" # if COOKIE_TYPE=3, configure the values of RAIL_EXPIRATION and RAIL_DEVICEID RAIL_EXPIRATION = "1577033439142" RAIL_DEVICEID = "PuV16sVaV-CTGsFZUuL8JLAk4OhuT1wgUYC_W3L2JZfWx8Ygx8LOPkko3PSOrK5_xSKhXjgyTMS8dBmj1RZHL2CKBTmVs6UG_yptlB4NJbGHldltrLMTUEgoDpSkpX2vzpGXgMQsTRzgOXfuQkAWwS4GjCxSmV3C" BIGipServerpassport=820510986.50215.0000 Route=9036359bb8a8a461c164a04f8f50b252 "# 1 = > always random ua,2- > Random once only when starting: ua RANDOM_AGENT = 2 PASSENGER_TICKER_STR = {'first class seat': 'first class seat': 'expensive seat': 'second class seat': 'oasis,' business seat': 9, 'hard seat': 1,'no seat': 1, 'soft seat': 2, 'soft berth': 4 "hard sleeper": 3,} # Protection 12306 official website request frequency Set random request time, the principle is no more than 80 times in 5 minutes # maximum interval request time MAX_TIME = 3 # minimum interval request time MIN_TIME = 1 # software version RE_VERSION = "1.2.003"

Step 2: filter CDN before startup

Python3 run.py c

Step 3: start the service

Python3 run.py r

After successfully grabbing tickets, the following results will appear:

Project address:

Https://github.com/testerSunshine/12306

What did the programmer do to grab the train ticket?

The fact that programmers write code in order to grab tickets can be traced back to when 12306 websites first appeared.

At the beginning of 2010, 12306 online ticket purchases just appeared, and a year later, programmers were already writing scripts to buy tickets on GitHub, but they were limited to querying the remaining tickets at that time.

Then, more and more programmers began to "program at home", and the biggest news was that they almost brought down GitHub.

In 2012, a plugin developed by a big shot named iFish was loaded with Spring Festival versions of many browsers, and even 12306 officials cited a resource in it.

This plug-in triggered the famous "12306 booking assistant dragged down GitHub" incident.

To put it simply, the file used by this "booking assistant" is not an ordinary static file (such as gist), but a raw data of repo.

This means that every time someone requests the file, GitHub accesses the repo to find the required data.

And, if a data request fails, the instruction will be requested every five seconds until it succeeds.

So during the rush hour for tickets more than ten days before the Spring Festival, the huge number of visitors caused Github to be attacked by DDOS and could not bear the load.

Afterwards, the author himself said: there was a lot of panic.

After that, with the emergence of a variety of App paid tickets, many people will not choose to code a pile of code just to grab a ticket, but the obsession in the programmer's heart will never be extinguished. "programming for home" is worth it.

The above content is how to use Python to get the ticket home. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report