Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write a Weibo lucky draw Mini Program based on Python

Shulou Source: shulou.com Published: 2022-05-31 17:16:04 10月04日 Update

This article mainly explains "how to write a Weibo lucky draw Mini Program based on Python", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to write a Weibo lucky draw Mini Program based on Python".

Development tools

Python version: 3.7.8

Related modules:

DecryptLogin module

DecryptLoginExamples module

And some modules that come with python.

Environment building

Install Python and add it to the environment variable, and pip installs the relevant modules you need.

be all eagerness to see it

First, pip installs the DecryptLoginExamples module:

Pip install DecryptLoginExamples

Then simply write a few lines of code to call ok:

From DecryptLoginExamples import clientconfig = {'username': user name,' password': password, 'interval between time_interval': queries on Weibo,} crawler_executor = client.Client () crawler_executor.executor (' weibolottery', config=config)

The effect is as follows:

Brief introduction of principle

The whole implementation process is similar to the previous article:

Do not want to roll in, the whole bilibili automatic raffle Mini Program bar, in case you accidentally get rich ~

Specifically, get your own Weibo follow-up list first:

Def getfollows (self, session): page, targetid_list = 0, [] while True: page + = 1 response = session.get ('https://m.weibo.cn/api/container/getIndex?containerid=231093_-_selffollowed&page={}'.format(page), headers=self.headers) profile_urls = re.findall (r' "profile_url": "(. *?)"' Response.text) if len (profile_urls) = 0: break for profile_url in profile_urls: targetid_list.append (re.findall (rroomuid = (. *?) &', profile_url) [0]) return targetid_list

Then regularly check whether the users they follow have posted new raffle information and then ok:

# iterate through the target users every once in a while and forward all Weibo with raffle information to self.logging ('initialization is complete, start automatically detecting Weibo related to raffle') while True: for targetid in targetid_list: print (F' is checking whether user {targetid} has posted a new raffle Weibo') weibos = self.getweibos (session Targetid) for card in weibos: if card ['mblog'] [' id'] in repost_weibos_dict [targetid]: continue else: repost_weibos_ targets [targetid] .append (card ['mblog'] [' id']) if 'raffle' in card ['mblog'] [' text']: self. Logging (f' detected a Weibo suspected to contain raffle information: {card}') # automatically like card_id = card ['mblog'] [' id'] response = session.get ('https://m.weibo.cn/api/config') st = response.json () [' data'] ['st'] flag) Response_json = self.starweibo (session, st, card_id, targetid) if flag: self.logging (f' automatically likes Weibo whose ID is {card_id}') else: self.logging (failed to automatically like Weibo whose ID is {card_id} The returned content is >\ n {response_json}') # automatic forwarding + comment flag, response_json = self.repost (session, st) Card_id) if flag: self.logging (f' automatic forwarding + comment ID {card_id} Weibo success') else: self.logging (f' automatic forwarding + comment ID {card_id} Weibo failure The returned content is >\ n {response_json}') print (f' detect whether the user {targetid} has posted a new lucky draw Weibo completed') time.sleep (self.time_interval)

Among them, the way to judge whether this Weibo post belongs to the lucky draw Weibo is:

If 'lucky draw' in card ['mblog'] [' text']: now that you have a better understanding of "how to write a Weibo lucky draw Mini Program based on Python", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Module user detection program content information comment success time environment learning query practical deeper preview almost code fully automatic interest dynamic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Docker Xiaomi macOS