-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweibo.py
More file actions
executable file
·26 lines (19 loc) · 921 Bytes
/
weibo.py
File metadata and controls
executable file
·26 lines (19 loc) · 921 Bytes
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
#!/usr/bin/env python3
import requests
from urllib.parse import urlencode
from today import Today, DEFAULT_HEADERS
class WeiboHot(Today):
name = 'weibo_hot'
desc = '微博热搜'
icon = 'https://raw.githubusercontent.com/maguowei/today/master/imgs/icon/weibo.png'
url = 'https://m.weibo.cn/api/container/getIndex?containerid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot&title=%E5%BE%AE%E5%8D%9A%E7%83%AD%E6%90%9C&extparam=filter_type%3Drealtimehot'
def crawler(self):
r = requests.get(self.url, headers=DEFAULT_HEADERS)
hots = r.json()['data']['cards'][0]['card_group']
data = []
for item in hots:
query = urlencode({'q': f"#{item['desc']}#", 'Refer': 'top'})
data.append({'title': item['desc'], 'url': f"https://s.weibo.com/weibo?{query}"})
return data
if __name__ == '__main__':
WeiboHot().export()