参考文:
https://blog.csdn.net/fei347795790/article/details/111164254 Python实现自动发送B站直播弹幕软件
https://blog.csdn.net/fzq13994952987/article/details/100861372 bilibili直播间利用python爬虫自动发送弹幕
https://www.bilibili.com/read/cv8186413/ Bilibili直播API消息内容解析
https://www.bilibili.com/read/cv12357091?from=articleDetail BilibiliAPI 合集 含个人、视频、直播等信息
发送弹幕
import requests
import time
def send():url = 'https://api.live.bilibili.com/msg/send'data = {'color': '16777215', # 颜色'fontsize': '25', # 字体大小'mode': '1', # 模式'msg': test, # 消息内容'rnd': str(int(time.time())), # 这个是时间戳'roomid': roomid, # 这个是直播房间的id号'bubble': '0','csrf_token': '复制自己的','csrf': '复制自己的',} cookie = {'Cookie':'自己的Cookie'}response = requests.post(url,data=data,cookies=cookie)# 系统对消息的敏感内容有屏蔽措施
接收监听弹幕消息
def barrage():url = "http://api.live.bilibili.com/ajax/msg?roomid="room = "需要监听的直播间房间号"res = requests.get(url+room).json()res = res['data']['room'][-1]print(res)