# -*- coding: utf-8 -*- # @Author: wangkun # @Time: 2023/2/10 from datetime import date, timedelta import requests import json from common.feishu import Feishu class Weixinzhishu: @classmethod def search_word(cls): return ["消息", "彻底", "现在", "真是", "突然", "消失", "太好了", "心声"] @classmethod def wechat_key(cls, log_type, crawler): sheet = Feishu.get_values_batch(log_type, crawler, 'sVL74k') for i in range(len(sheet)): search_key = sheet[1][1] openid = sheet[1][2] return search_key, openid @classmethod def weixinzhishu(cls, log_type, crawler, query): wechat_key = cls.wechat_key(log_type, crawler) search_key = wechat_key[0] openid = wechat_key[-1] start_ymd = (date.today() + timedelta(days=-1)).strftime("%Y-%m-%d").replace("-", "") end_ymd = (date.today() + timedelta(days=-8)).strftime("%Y-%m-%d").replace("-", "") print(f"search_key:{search_key}") print(f"openid:{openid}") print(f"start_ymd:{start_ymd}") print(f"start_ymd:{end_ymd}") url = "https://search.weixin.qq.com/cgi-bin/wxaweb/wxindex" payload = json.dumps({ "openid": openid, "search_key": search_key, "cgi_name": "GetDefaultIndex", "start_ymd": "20230206", "end_ymd": "20230210", "query": query }) headers = { 'Host': 'search.weixin.qq.com', 'content-type': 'application/json', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.32(0x1800202a) NetType/WIFI Language/zh_CN', 'Referer': 'https://servicewechat.com/wxc026e7662ec26a3a/42/page-frame.html' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) time_index = response.json()['content']['resp_list'][0]['indexes'][0]['time_indexes'] print(time_index) if __name__ == "__main__": Weixinzhishu.weixinzhishu('weixin', 'weixinzhishu', '狂飙')