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

基于Python編寫一個(gè)微博抽獎(jiǎng)小程序

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

導(dǎo)語(yǔ)

帶大家寫個(gè)微博自動(dòng)抽獎(jiǎng)小程序吧,motivation和之前的B站自動(dòng)抽獎(jiǎng)小程序一樣:

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

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

開發(fā)工具

Python版本:3.7.8

相關(guān)模塊:

DecryptLogin模塊;

DecryptLoginExamples模塊;

以及一些python自帶的模塊。

環(huán)境搭建

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

先睹為快

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

pip install DecryptLoginExamples

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

from DecryptLoginExamples import client

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

效果如下:

原理簡(jiǎn)介

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

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

具體而言,就是先獲取自己微博的關(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

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

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

其中,判斷這條微博是否屬于抽獎(jiǎng)微博的方式是:

if '抽獎(jiǎng)' in card['mblog']['text']:

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

ok,大功告成啦

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

相關(guān)文章

最新評(píng)論