您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“基于Python怎么編寫一個(gè)微博抽獎(jiǎng)小程序”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“基于Python怎么編寫一個(gè)微博抽獎(jiǎng)小程序”吧!
Python版本:3.7.8
相關(guān)模塊:
DecryptLogin模塊;
DecryptLoginExamples模塊;
以及一些python自帶的模塊。
安裝Python并添加到環(huán)境變量,pip安裝需要的相關(guān)模塊即可。
首先,pip安裝一下DecryptLoginExamples模塊:
pip install DecryptLoginExamples
然后簡單寫幾行代碼調(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)
效果如下:
整個(gè)實(shí)現(xiàn)流程和之前的這篇文章差不多:
不想內(nèi)卷了,整個(gè)B站全自動(dòng)抽獎(jiǎng)的小程序吧,萬一不小心暴富了呢~
具體而言,就是先獲取自己微博的關(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í)檢測自己關(guān)注的用戶有沒有發(fā)布新的抽獎(jiǎng)信息就ok了:
# 每隔一段時(shí)間遍歷一遍目標(biāo)用戶, 把有抽獎(jiǎng)信息的微博都轉(zhuǎn)發(fā)一遍 self.logging('初始化完成, 開始自動(dòng)檢測抽獎(jiǎng)相關(guān)的微博') while True: for targetid in targetid_list: print(f'正在檢測用戶{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'檢測到一條疑似含有抽獎(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ā)+評論 flag, response_json = self.repost(session, st, card_id) if flag: self.logging(f'自動(dòng)轉(zhuǎn)發(fā)+評論ID為{card_id}的微博成功') else: self.logging(f'自動(dòng)轉(zhuǎn)發(fā)+評論ID為{card_id}的微博失敗, 返回的內(nèi)容為 >>>\n{response_json}') print(f'檢測用戶{targetid}是否發(fā)布了新的抽獎(jiǎng)微博完成') time.sleep(self.time_interval)
其中,判斷這條微博是否屬于抽獎(jiǎng)微博的方式是:
if '抽獎(jiǎng)' in card['mblog']['text']:
到此,相信大家對“基于Python怎么編寫一個(gè)微博抽獎(jiǎng)小程序”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。