Python獲取B站直播中的最新一條評論,複製內容傳送到該直播間中
阿新 • • 發佈:2018-12-26
注意:
不要在一個直播間浪太久,會被拉黑的,說不定會被罵[哭唧唧]
# encoding=utf-8 # Created by double lin at 2018/10/10 import requests # 獲取最新的彈幕列表,並輸出內容 # cookie = { # 'cookies': 'dadfasdf' # } def dm(): form_data = { 'roomid': '7734200', 'csrf_token': '3b32519208d74007f5df36247f535517', 'visit_id': '' } res = requests.post('https://api.live.bilibili.com/ajax/msg', data=form_data) text = res.json()['data']['room'][-1]['text'] return text def send(msg): form_data = { 'color': '16777215', 'fontsize': '25', 'mode': '1', 'msg': msg, 'rnd': '1539131561', 'roomid': '7734200', 'csrf_token': '3b32519208d74007f5df36247f535517' } cookie = { 'Cookie': 'sid=85eo9p1i; fts=1535796133; LIVE_BUVID=AUTO4815357971941568; stardustvideo=1; CURRENT_FNVAL=8; buvid3=F75C5C53-B663-45C8-9D2B-524E2C77416316076infoc; rpdid=xopkiolwidosksmlmiww; im_notify_type_255205669=0; UM_distinctid=165f12aa47f759-08e60c59840eb3-3a61430c-1fa400-165f12aa480755; im_local_unread_255205669=0; DedeUserID=255205669; DedeUserID__ckMd5=5a90d485af6a99f0; SESSDATA=a3ee9543%2C1540518411%2C434a9de3; bili_jct=3b32519208d74007f5df36247f535517; CURRENT_QUALITY=0; finger=edc6ecda; bsource1=undefined; bsource=seo_baidu; _dfcaptcha=29211fa38f3d3500b42a89f464a47c43; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1537331358,1537404239,1539131525; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1539131564' } res2 = requests.post('https://api.live.bilibili.com/msg/send', cookies=cookie, data=form_data) s = '' while True: msg = dm() if (s == msg): continue else: send(msg) s = msg print(msg)