bilibili发送弹幕

前言

媳妇儿玩起了bilibili直播,我就顺便研究下利用python发送弹幕,以表支持~,主要思路通过发送http请求。

发送弹幕

1. 查询http请求

首先登录b站,进入直播间,打开开发者工具,先在直播间发送一条弹幕。

可以看到请求的url地址,请求方式是post,以及请求的表单数据:
在这里插入图片描述

2. 查询自己账号cookie和user-agent信息

打开开发者工具,进入个人中心/首页:
在这里插入图片描述

3. 代码

import requests
import time

class bullet_screen():
    def __init__(self, room_id):
        self.room_id = room_id
        self.send_url = "https://api.live.bilibili.com/msg/send"
        self.cookie = {
   'Cookie' : '填入上图查询到的cookie'}
        self.header = {
   'User-Agent' : '填入上图查询到的userAgent'}

        self.send_data = {
   
            'color': 16777215,
            'fontsize': 25,
            'mode': 1,
            'msg': '123',
            'rnd': 1582471255,
            'roomid': room_id,
            'bubble': 0,
            'csrf_token': '44d0e7f3eaea7ff05774822e8eaf49b2',
            'csrf': '44d0e7f3eaea7ff05774822e8eaf49b2'
        }

    def send(self, msg):
        self.send_data['rnd'] = time.time() #获得当前的时间戳
        self.send_data['msg'] = msg
        reponse = requests.post(self.send_url
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值