Python获取QQ等级加速信息
准备环境
1、python 3.7+
2、依赖:json、httpx、re、asyncio
代码实现
点我查看代码~
import json
import httpx
import re
import asyncio
async def QQ_get_level_1(cookie: str):
url = "https://ti.qq.com/qqlevel/index"
querystring = {"_wv": "3", "_wwv": "1", "tab": "7", "source": "1"}
headers = {
"Host": "ti.qq.com",
"User-Agent": "Mozilla/5.0 (Linux; Android 10; MI 8 Lite Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/109.0.5414.86 MQQBrowser/6.2 TBS/046613 Mobile Safari/537.36 V1_AND_SQ_8.9.73_4416_YYB_D QQ/8.9.73.11945 NetType/WIFI WebP/0.3.0 AppId/537171693 Pixel/1080 StatusBarHeight/82 SimpleUISwitch/0 QQTheme/1000 StudyMode/0 CurrentMode/0 CurrentFontScale/1.0 GlobalDensityScale/0.9818182 AllowLandscape/false InMagicWin/0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/wxpic,image/sharpp,image/apng,image/tpg,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie": cookie,
"content-type": "application/json"
}
async with httpx.AsyncClient() as client:
res = await client.post(url, headers=headers, params=querystring)
res.encoding = "utf-8"
res = res.text
begin_str = 'window.__INITIAL_STATE__='
end_str = ';'
re_list = re.findall(f'{begin_str}(.*?){end_str}', res)
text = {}
text['type'] = 'QQ等级查询'
text['auth'] = 'XD Team'
if len(re_list) == 0:
text['code'] = '-1'
return text
re_data = json.loads(re_list[0])
text['code'] = '200'
text['加速信息'] = []
text['昵称'] = re_data['qqLevelInfo'].get('sNickName')
text['已加速天数'] = re_data['levelInfo']['levelProgress'].get('curLevelDays')
text['需加速天数'] = re_data['levelInfo']['levelProgress'].get('curLevelTotalDays')
text['当前等级'] = re_data['levelInfo']['oriInfo'].get('oriLevel')
text['好友排名'] = re_data['levelInfo']['oriInfo'].get('oriRank')
for item in re_data['taskList']:
_text = {}
_text[item.get('title')] = {}
_text[item.get('title')]['status'] = False if item['status'] == 0 else True
_text[item.get('title')]['days'] = item['finishedAccelerateDays']
text['加速信息'].append(_text)
text['total'] = len(text['加速信息'])
return text
测试
调用方式:print(json.dumps(asyncio.run(QQ_get_level_1(cookie))))