python爬bilibili弹幕

import requests
import time
#统一资源定位符   ' "  单双无区别  '''三引号支持多行,类似pre标签
url = 'https://api.live.bilibili.com/ajax/msg'
#要提交的数据
form = {'roomid':'79558',
'token':'',
'csrf_token':'e7fa015936c1ccb7f08d06a2801d3180'}
#提交数据给urlurl返回弹幕(datapost函数中默认的参数)
while True:
    time.sleep(2)
    html = requests.post(url, data=form)
    # json 提取数据
    content = list(map(lambda ii: html.json()['data']['room'][ii]['text'], range(10)))
    print(content)

你可能感兴趣的:(python笔记)