From 696fb2bc8e30d573ef68bf94f4fb3753385ad217 Mon Sep 17 00:00:00 2001 From: CharlesPikachu <1159254961@qq.com> Date: Sun, 15 May 2022 17:55:36 +0800 Subject: [PATCH] update docs --- docs/cn/EXAMPLES.md | 31 +++++++++++++++++++ .../crawlers/weibolottery/weibolottery.py | 10 +++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/cn/EXAMPLES.md b/docs/cn/EXAMPLES.md index 294cbf9..62c090a 100644 --- a/docs/cn/EXAMPLES.md +++ b/docs/cn/EXAMPLES.md @@ -771,4 +771,35 @@ config = { } crawler_executor = client.Client() crawler_executor.executor('weiboblacklist', config=config) +``` + +#### 微博自动转发抽奖 + +**1.相关依赖** + +在终端运行如下命令即可安装运行该项目所需要的相关依赖包: + +```sh +pip install DecryptLoginExamples +``` + +**2.环境配置** + +- 操作系统: Linux or macOS or Windows +- Python版本: Python3.6+ + +**3.调用方式** + +脚本调用方式如下: + +```python +from DecryptLoginExamples import client + +config = { + 'username': 用户名, + 'password': 密码, + 'time_interval': 查询微博动态的间隔时间, +} +crawler_executor = client.Client() +crawler_executor.executor('weibolottery', config=config) ``` \ No newline at end of file diff --git a/examples/DecryptLoginExamples/crawlers/weibolottery/weibolottery.py b/examples/DecryptLoginExamples/crawlers/weibolottery/weibolottery.py index 13351c4..0a8e27c 100644 --- a/examples/DecryptLoginExamples/crawlers/weibolottery/weibolottery.py +++ b/examples/DecryptLoginExamples/crawlers/weibolottery/weibolottery.py @@ -35,20 +35,22 @@ class WeiboLottery(): for targetid in targetid_list: repost_weibos_dict[targetid] = [] # 每隔一段时间遍历一遍目标用户, 把有抽奖信息的微博都转发一遍 + self.logging('初始化完成, 开始自动检测抽奖相关的微博') for targetid in targetid_list: + print(f'正在检测用户{targetid}是否发布了新的抽奖微博') 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']: + 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) + flag, response_json = self.starweibo(session, st, card_id, targetid) if flag: self.logging(f'自动点赞ID为{card_id}的微博成功') else: @@ -91,10 +93,10 @@ class WeiboLottery(): return True, response.json() return False, response.json() '''自动点赞''' - def starweibo(self, session, st, card_id): + def starweibo(self, session, st, card_id, targetid): session.headers.update({ 'origin': 'https://m.weibo.cn', - 'referer': f'https://m.weibo.cn/u/{self.targetid}?uid={self.targetid}', + 'referer': f'https://m.weibo.cn/u/{targetid}?uid={targetid}', }) data = { 'id': card_id,