forked from liyf-code/reverse_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
67 lines (53 loc) · 1.76 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# _*_ coding: utf-8 _*_
# @Date: 5:57 下午
# @File: demo.py
# @Author: liyf
import execjs
import requests
from loguru import logger
f = open('demo.js', 'r')
js_str = f.read()
ctx = execjs.compile(''.join(js_str))
headers = {
"authority": "api.weibotop.cn",
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh-CN,zh;q=0.9",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
}
def get_timeid_dec_data(timeid, encrypt_data):
if timeid:
return ctx.call('l', timeid)
return ctx.call('h', encrypt_data)
def get_latest_date():
'''
获取最新一次的热搜日期
:return:
'''
url = "https://api.weibotop.cn/getlatest"
response = requests.get(url, headers=headers)
return response.json()
def get_data(timeid):
url = "https://api.weibotop.cn/currentitems"
enc_timeid = get_timeid_dec_data(timeid, encrypt_data=None)
logger.info(f'timeid: {enc_timeid}')
params = {
"timeid": enc_timeid
}
response = requests.get(url, headers=headers, params=params)
return response.text
def main():
latest_res = get_latest_date()
timeid = latest_res[0]
latest_date = latest_res[1]
logger.info(f'最近一次更新日期为: {latest_date}')
encrypt_data = get_data(timeid)
decrypt_data = get_timeid_dec_data(timeid=None, encrypt_data=encrypt_data)
for data in decrypt_data:
title = data[0]
rank_list_date = data[1]
last_rank_list = data[2]
heat = data[3]
print(f'热搜名称: {title}\n上榜时间: {rank_list_date}\n最后在榜: {last_rank_list}\n热度: {heat}')
print('***' * 20)
if __name__ == '__main__':
main()