-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgetRoomInfo.py
25 lines (24 loc) · 1.09 KB
/
getRoomInfo.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
import sys
import json
import requests
import re
import urllib
if __name__ == '__main__':
url = 'https://live.douyin.com/%s' % sys.argv[1]
h = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'cookie': '__ac_nonce=0638733a400869171be51',
}
res = requests.get(url=url, headers=h)
data = res.cookies.get_dict()
ttwid = data['ttwid']
res = res.text
res = re.search(r'<script id="RENDER_DATA" type="application/json">(.*?)</script>', res)
res = res.group(1)
res = urllib.parse.unquote(res, encoding='utf-8', errors='replace')
res = json.loads(res)
roomStore = res['app']['initialState']['roomStore']
liveRoomId = roomStore['roomInfo']['roomId']
liveRoomTitle = roomStore['roomInfo']['room']['title']
sys.stdout.write(json.dumps({'url':url,'liveRoomId':liveRoomId,'liveRoomTitle':liveRoomTitle}))