Python realizes automatic sending of barrage in the live broadcast room, so that the meinv anchor can see you at a glance

foreword

Dididi, your favorite female anchor is live~

insert image description here

Every time I watch the live broadcast, I don’t know if you have thought about letting the anchor see your barrage! However, there are too many bullet screens and the anchors can’t see it, so I want to keep scrolling, but the manual one is a bit slow... Shall we try the automatic one?

You can't learn python for nothing

insert image description here

Preparation

Development environment:

Software tools used:

Python 3.8 to run the code

pycharm 2022.3.2 Auxiliary Knock Code Professional Edition

Third-party modules need to be installed:

  • requests >>>> Function: send request

Third-party module installation:

  1. win + R, enter cmd and click OK, enter the installation command pip install module name (pip install requests) and
    press Enter
  2. Click Terminal (terminal) in pycharm to enter the installation command

implement the code

module

import requests
import time
from tkinter import *
import random

Barrage text [can be modified by yourself]

lis_text = ['666', '主播真厉害',
            '爱了,爱了',
            '关注走一走,活到99',
            '牛逼!!!',
            '秀儿,是你吗?']
def send():
    a = 0
    while True:
        time.sleep(2)
        send_meg = random.choice(lis_text)
        roomid = entry.get()
        ti = int(time.time())
        url = 'https://api.live.****.com/msg/send'
        data = {
    
    
            'color': '16777215',
            'fontsize': '25',
            'mode': '1',
            'msg': send_meg,
            'rnd': '{
    
    }'.format(ti),
            'roomid': '{
    
    }'.format(roomid),
            'bubble': '0',
            'csrf_token': '08d11cd34efbf3da0d2138d562145e5c',
            'csrf': '08d11cd34efbf3da0d2138d562145e5c',
        }

        headers = {
    
    
完整源码、解答、教程皆+VX:xiaoyuanllsll获取,记得验证备注“y”
            'cookie': '_uuid=50D22ECF-208D-9409-DEA1-0B3EA3F74AB793744infoc; buvid3=A0FE83C2-5981-40DC-B0E2-C74A37227ECF155818infoc; rpdid=|(umuummlkY~0J\'ulm|ullmll; sid=kr4i59d5; LIVE_BUVID=AUTO3215909029132687; blackside_state=1; CURRENT_FNVAL=80; DedeUserID=406732493; DedeUserID__ckMd5=48c43aca436bb747; SESSDATA=204f478b%2C1615703177%2C53385*91; bili_jct=08d11cd34efbf3da0d2138d562145e5c; dy_spec_agreed=1; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1598946515,1600327358; bp_video_offset_406732493=463816176887860111; _dfcaptcha=90896a21dabbab6ef641f2e393b46913; bsource=search_baidu; PVID=6',
            'origin': 'https://live.****.com',
            'referer': 'https://live.****.com/blanc/1029?liteVersion=true',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
        }
        a += 1
        response = requests.post(url=url, data=data, headers=headers)
        print(response)
        text.insert(END, '第{
    
    }条弹幕发送成功'.format(a))
        # 文本框滚动
        text.see(END)
        # 更新
        text.update()
        text.insert(END, '发送内容:{}'.format(send_meg))


root = Tk()
root.title('B站自动发送弹幕')
root.geometry('560x450+400+200')
完整源码、解答、教程皆+VX:xiaoyuanllsll
label = Label(root, text='请输入房间ID:', font=('华文行楷', 20))
label.grid()

entry = Entry(root, font=('隶书', 20))
entry.grid(row=0, column=1)

text = Listbox(root, font=('隶书', 16), width=50, heigh=15)
text.grid(row=2, columnspan=2)

button1 = Button(root, text='开始发送', font=('隶书', 15), command=send)
button1.grid(row=3, column=0)

button2 = Button(root, text='退出程序', font=('隶书', 15), command=root.quit)
button2.grid(row=3, column=1)

root.mainloop()

Approximate interface

insert image description here

at last

Today’s article sharing ends here. If you need the code, you can directly click on the business card at the end of the article~

Don't forget to note

Guess you like

Origin blog.csdn.net/aliYz/article/details/131237099