欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python編寫一個微博抽獎小程序

 更新時間:2022年05月16日 11:19:03   作者:白露未晞me  
本文將利用Python編寫一個微博抽獎小程序,夢想總是要有的,萬一靠在微博上自動抽獎暴富了呢~文中的示例代碼講解詳細(xì),感興趣的可以了解一下

導(dǎo)語

帶大家寫個微博自動抽獎小程序吧,motivation和之前的B站自動抽獎小程序一樣:

不想內(nèi)卷了,整個B站全自動抽獎的小程序吧,萬一不小心暴富了呢~

廢話不多說,讓我們愉快地開始吧~

開發(fā)工具

Python版本:3.7.8

相關(guān)模塊:

DecryptLogin模塊;

DecryptLoginExamples模塊;

以及一些python自帶的模塊。

環(huán)境搭建

安裝Python并添加到環(huán)境變量,pip安裝需要的相關(guān)模塊即可。

先睹為快

首先,pip安裝一下DecryptLoginExamples模塊:

pip install DecryptLoginExamples

然后簡單寫幾行代碼調(diào)用就ok啦:

from DecryptLoginExamples import client

config = {
    'username': 用戶名,
    'password': 密碼,
    'time_interval': 查詢微博動態(tài)的間隔時間,
}
crawler_executor = client.Client()
crawler_executor.executor('weibolottery', config=config)

效果如下:

原理簡介

整個實現(xiàn)流程和之前的這篇文章差不多:

不想內(nèi)卷了,整個B站全自動抽獎的小程序吧,萬一不小心暴富了呢~

具體而言,就是先獲取自己微博的關(guān)注列表:

'''獲得關(guān)注的用戶列表'''
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(r'uid=(.*?)&', profile_url)[0])
    return targetid_list

然后定時檢測自己關(guān)注的用戶有沒有發(fā)布新的抽獎信息就ok了:

# 每隔一段時間遍歷一遍目標(biāo)用戶, 把有抽獎信息的微博都轉(zhuǎn)發(fā)一遍
self.logging('初始化完成, 開始自動檢測抽獎相關(guān)的微博')
while True:
    for targetid in targetid_list:
        print(f'正在檢測用戶{targetid}是否發(fā)布了新的抽獎微博')
        weibos = self.getweibos(session, targetid)
        for card in weibos:
            if card['mblog']['id'] in repost_weibos_dict[targetid]: 
                continue
            else:
                repost_weibos_dict[targetid].append(card['mblog']['id'])
            if '抽獎' in card['mblog']['text']:
                self.logging(f'檢測到一條疑似含有抽獎信息的微博: {card}')
                # 自動點贊
                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'自動點贊ID為{card_id}的微博成功')
                else:
                    self.logging(f'自動點贊ID為{card_id}的微博失敗, 返回的內(nèi)容為 >>>\n{response_json}')
                # 自動轉(zhuǎn)發(fā)+評論
                flag, response_json = self.repost(session, st, card_id)
                if flag:
                    self.logging(f'自動轉(zhuǎn)發(fā)+評論ID為{card_id}的微博成功')
                else:
                    self.logging(f'自動轉(zhuǎn)發(fā)+評論ID為{card_id}的微博失敗, 返回的內(nèi)容為 >>>\n{response_json}')
        print(f'檢測用戶{targetid}是否發(fā)布了新的抽獎微博完成')
    time.sleep(self.time_interval)

其中,判斷這條微博是否屬于抽獎微博的方式是:

if '抽獎' in card['mblog']['text']:

即微博正文中存在抽獎這兩個字的時候,我們就對該微博進(jìn)行點贊,自動轉(zhuǎn)發(fā)和評論操作,所以可能存在誤轉(zhuǎn)的情況。不過這玩意應(yīng)該是屬于寧濫勿缺吧。

ok,大功告成啦

到此這篇關(guān)于基于Python編寫一個微博抽獎小程序的文章就介紹到這了,更多相關(guān)Python微博抽獎內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論