[Python script] Python automatically grabs tickets on Damai.com, sells concert tickets on time at the original price, and refuses scalping transactions! Start from me! ! !

In order to help everyone gain a greater chance of success in the fierce competition to grab tickets, this article will introduce the implementation principles of ticket grabbing software and some of the ticket grabbing methods that I know.
However, please don’t place your hopes too much on the ticket-grabbing software. Sometimes it doesn’t work. After my verification, even if you use the ticket-grabbing software, you may not be able to grab the tickets.
The ticketing platform will often adjust the anti-crawling strategy to combat crawler behavior. If you want the ticket grabbing software to maintain a high success rate, developers need to make logical adjustments to the ticketing platform’s crackdown strategy. This cost is very high, so you can easily get it. There is a high probability that the ticket grabbing software will not be able to grab tickets or it is unsafe.
During the research process, I discovered an interesting point: "Scalpers never steal tickets." Relevant regulations stipulate that the number of commercial performance tickets sold to the market shall not be less than 70% of the approved number of audiences. The remaining 30%, which are non-publicly sold tickets, are the main source of scalper tickets, also called channel tickets. This involves the organizer’s ticket sales strategy for hot tickets and cold tickets. Scalpers play an important role in this chain. As long as the secondary market for concert tickets does not disappear, scalpers will never disappear. For the market itself , People who are willing to spend more money to buy scalper tickets must be people with greater needs. Scalpers are just the personification of market regulation.

1. Analyze the ticket purchasing process

Nowadays, whether you buy train tickets, airplane tickets, or concert tickets, you basically use electronic payment to buy tickets online. After that, you get an electronic ticket voucher and print the paper ticket or the QR code of the ticket verification ticket before entering the venue. So let’s look at what a complete ticket purchasing process looks like from the user’s perspective.Insert image description here

User’s ticket purchase process:

  1. First, users log in to the ticketing APP to search for idol tickets, click to view ticket details, and then select the event and ticket slot. Wait for the countdown to grab tickets before you can enter the next page;
  2. .After the countdown ends, the grab button is lit, and the user enters the next step to select the performer, confirm the information, and select the payment method to submit the order;
  3. If you are fast enough and lucky enough, if you grab the ticket, the selected payment method APP will be activated to prompt for payment; if you do not grab the ticket, it will prompt congestion and jump to the ticket stall selection page. Next, I will supplement this picture and think about which steps are the key time nodes for users to improve the success rate of ticket issuance:Insert image description here

Obviously, the page that the user cannot see before the countdown is the key time to compete for hand speed. When the grab button is lit by the countdown, click as quickly as possible to reach the hidden page, and then select the performer. Usually the default payment method is used and the order is submitted last. Once the order is submitted successfully, it means you have locked the seat and grabbed the ticket. If the user fails to pay within the stipulated time, the seat will flow back into the ticket pool, and anyone who misses it can grab it. At this point, we know the ticket purchase process and the breakthrough point to improve the success rate of ticket grabbing. Human hand speed is definitely not as fast as a machine. Next, we will introduce two commonly used technical ticket grabbing solutions.

2. Selenium simulates browser operations

When using the Chrome browser, users can use mouse sliding, key clicks, and keyboard input as signal input devices to convey instructions to the browser, and the browser executes rendering after receiving the instructions. The Selenium WebDriver mentioned here encapsulates the native API provided by the browser. Using this set of APIs, you can control the opening and closing of the browser, open web pages, operate interface elements, and control cookies. To put it simply, you can automatically realize the input of user mouse and keyboard signals by writing code. In this way, there are a lot of things that can be done.
The following is a simple script. It first opens the chrome browser and enters Google's URL, waits for 5 seconds. After the browser webpage opens, find the input box and enter "ChromeDriver", and then simulates clicking the search button, and you can see the search results on the browser. result.

import time

from selenium import webdriver
from selenium.webdriver.common.by import By

browser.get("https://www.google.com")
time.sleep(5)
# 查找元素
search_box = browser.find_element(By.NAME, 'q')
# 模拟按键输入
search_box.send_keys('ChromeDriver')
# 搜索框模拟回车
search_box.submit()
time.sleep(5)
# 关闭所有窗口
browser.quit()

Back to the topic of grabbing tickets, we can use this technical ability to write a Python script and execute it on the local machine. The content of the script is to open the browser at the specified time, open the ticketing webpage, and then automatically simulate the user to select the moviegoer and then automatically submit the order. (I originally wanted to make a demonstration video here, which is more intuitive to understand, but time and energy are limited, so I will not introduce the Selenium WebDriver development environment configuration in detail here. If you are interested, you can continue to dig deeper).

3. Reverse engineering: ticket grabbing interface

What is inversion? That is, technical means are used to capture the communication traffic of the ticketing APP, locate the key requests for obtaining ticket stalls and submitting orders, decrypt the https traffic, and then analyze and decrypt the traffic data.Insert image description here

Let’s continue to return to this picture. If you look closely, you will find that some actions such as viewing ticket details and selecting ticket stalls are all done on the APP and are loaded in advance. What really determines the user’s ticket grabbing is the “submit order” Key requests. If we can capture the traffic of this request and then analyze its parameter construction rules, we can write a program to automatically send the request.Insert image description here

In the following packet capture example, a ticket is selected and its ticket information is obtained through packet capture.Insert image description here

By analogy, capture the packet ordering interface to observe its parameter composition, and write a program to simulate user requests.

# 等待开售
def wait_for_buy():
    # 抢购时间
    start_timestamp = 1686475533
    # 当前时间
    current_timestamp = int(time.time())
    while current_timestamp > start_timestamp:
        # 开始购买
        place_order()

Here is a brief introduction to the implementation ideas and directions without going into the details of the reverse process. The specific implementation is not that simple. If there is an attacker, there must be a defender. In order to protect the interests of the platform, the ticketing party will inevitably define an attack strategy. For example, we will see an iterative process of the verification code from text to picture to slider verification. . The technical aspect is a problem, and the legal aspect is also a problem, so it should be treated as an offensive and defensive drill, and do not harm the interests of the ticketing party.

4. Final summary

Life is fucked up sometimes, and we may feel powerless, but please keep your passion and don’t let it be destroyed by setbacks. I wish everyone can get their favorite concert tickets at normal prices when buying tickets ~

Technical reserves about Python

Here I would like to share with you some free courses for everyone to learn. Below are screenshots of the courses. Scan the QR code at the bottom to get them all.

1. Python learning routes in all directions

Insert image description here

2. Learning software

If a worker wants to do his job well, he must first sharpen his tools. The commonly used development software for learning Python is here, saving everyone a lot of time.
Insert image description here

3. Study materials

Insert image description here

4. Practical information

Practice is the only criterion for testing truth. The compressed packages here can help you improve your personal abilities in your spare time.
Insert image description here

5. Video courses

Insert image description here

Well, today’s sharing ends here. Happy time is always short. Friends who want to learn more courses, don’t worry, there are more surprises~Insert image description here

Guess you like

Origin blog.csdn.net/Everly_/article/details/133211545