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 code to realize the lottery assistant to participate in the lottery automatically

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces how to use python code to achieve automatic participation of lottery assistants in the lottery, the content is very detailed, interested friends can refer to, I hope it can be helpful to everyone.

I wonder if you have used Mini Program, the assistant of raffle draw. (make a small advertisement for the lucky draw assistant for free). I have used it to distribute a lot of prizes on the official account many times. At the same time, I also participate in some lucky draw every day. The current winning record is 0 (embarrassed face).

You don't have to pay a penny to participate in the raffle among assistants, but it takes time. If you want to raffle, you have to open Mini Program one by one to participate. The operation repeated every day feels very tedious, so I came up with an idea. Use the program to automatically participate in the raffle.

Just do it, and those who are familiar with the basic principles of reptiles can probably guess what to do. We have written a series of tutorials based on the official Wechat crawler based on Python, and now assume that you already know how to use Fiddler to proxy HTTP requests.

After configuring the Fiddler, after the mobile phone opens the Mini Program "raffle assistant", there is a public raffle list.

Through the Fiddler grab package, we can see that the request address of the lucky draw list is / public_lottery?page=1&size=5, the request method is GET, and there is a Header field Authorization. The returned data structure clearly shows that a total of 5 pieces of data are returned, representing 5 prizes, and the meaning of each field can be basically guessed.

Let's manually select an activity and click to participate in the lottery to see how it sends the request to the server. After figuring out the principle, we can use the program to automatically simulate the request.

There are several things to note about the request to participate in the raffle. The request uses the POST method, the URL address is / lottery/67c3a5afe794dc7bdbed85a38a18bb44/join, and like the raffle list, another request Header is Authorization, whose value is the string at the beginning of a long string of Bearer. .

Now we can use Python to build a script that automatically participates in the lottery, automatically brushing it every once in a while, and automatically participating in the lottery when we find a new prize.

Source code # coding=utf-8

Import requests

Def main ():

Url = "https://lucky.nocode.com/public_lottery?page=1&size=5"

# replace it with your own Authorization

Headers = {

"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXV...."}

Res = requests.get (url, headers=headers)

Lotteries = res.json () .get ("data")

Join_url = "https://lucky.nocode.com/lottery/{id}/join"

For lottery in lotteries:

Res = requests.post (join_url.format (id=lottery.get ("id")), headers=headers)

Data = res.json ()

If res.status_code = = 200and 'errors' not in data:

Print ("successful participation in the lucky draw:"% s ""% lottery.get ("prizes") .get ("data") [0] .get ("name"))

If _ _ name__ = ='_ _ main__':

Main ()

Running

Successfully participate in the lucky draw: "Armani red tube lip glaze" successfully participated in the lucky draw: "Havaianas flip-flops" successfully participated in the lucky draw: "Don't be a boring adult", "successfully participated in the lucky draw:" Satan key chain "successfully participated in the lucky draw:" Desktop Thread "

Now that all the prizes are in a state of participation, wait for the winner. You can also improve the code.

Some people may ask, is this cheating? I think this is the advantage of programmers, we just use different tools to accomplish the same thing, programming is really a basic skill that everyone should master, nothing to write code to solve tedious and repetitive work. Laziness is the driving force to promote the progress of social civilization.

Let's hand out another lucky draw.

On how to use python code to achieve the lottery assistant automatically participate in the lottery to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report