Article directory
write in front
Sending barrage is just one of the small functions. You can also automatically like, favorite, coin, auto play, private message, etc., but we only demonstrate this, and the others will not be displayed.
Implementation steps
First open a video or live broadcast, F12 to open the developer tools, and click network. Then click this to clear it
, and then send a barrage, and then you can see the send, there is a post request. Click on the payload to see the barrage related data we just sent
and then write the code
First import the module
import random
import time
this is our url
url = 'https://api.live.bi******.com/msg/send'
# 某些原因我就不打全了
Receive the data parameter
data = {
'bubble': '0',
'msg': 6666,
'color': '16777215',
'mode': '1',
'fontsize': '25',
'rnd': '1640181316',
'roomid': '22819508',
'csrf': '131d24bf2b92a3609208ed83758ab8f2',
'csrf_token': '131d24bf2b92a3609208ed83758ab8f2',
}
Then the headers request header is here, and everything is added to it.
headers = {
'cookie': '_uuid=CF79473B-0F83-6087-BCB0-23A7E36C479296281infoc; buvid3=8AEBDC64-0CEE-4F6F-9866-B1508FAB2871148805infoc; blackside_state=1; rpdid=|(kmJY|kmu|)0J\'uYJRYkJu|Y; CURRENT_QUALITY=32; buvid_fp=8AEBDC64-0CEE-4F6F-9866-B1508FAB2871148805infoc; video_page_version=v_old_home; sid=abkn3and; i-wanna-go-back=-1; b_ut=5; bp_video_offset_65901796=602085772740229500; LIVE_BUVID=AUTO5916400017585242; CURRENT_BLACKGAP=1; CURRENT_FNVAL=2000; b_lsid=FB21108D7_17DE26BCC89; fingerprint=3c7949ca118951ae1be0b5b37b321306; buvid_fp_plain=556F173C-C5B7-4583-86F9-FD1074EB421D143076infoc; DedeUserID=523606542; DedeUserID__ckMd5=909861ec223d26d8; SESSDATA=cec4dda4%2C1655733287%2Cc5b88*c1; bili_jct=131d24bf2b92a3609208ed83758ab8f2; innersign=0; _dfcaptcha=fbb016616944e9b94331aeb2627c9d3d; PVID=3',
'origin': 'https://live.bi****.com',
'referer': 'https://live.bi****.com/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
}
Receive data
response = requests.post(url=url, data=data, headers=headers)
output
print(response.text)
This is the simplest version, just four lines of code.
I found a video that no one watched and ran it, and sent a hello.
What if you want to post more?
give it a list
lis = ['主播666', '主播真帅', '666']
The imported random module is to randomly pick a barrage
word = random.choice(lis)
Then we are writing an infinite loop
while True:
lis = ['主播666', '主播真帅', '666']
word = random.choice(lis)
The imported time is a delay function. After we send each time, we delay it for five seconds and put it at the end.
time.sleep(5)
Let's take a look at the effect again,
all the code
import random
import time
while True:
lis = ['主播666', '主播真帅', '666']
word = random.choice(lis)
url = 'https://api.live.bi****.com/msg/send'
data = {
'bubble': '0',
'msg': word,
'color': '16777215',
'mode': '1',
'fontsize': '25',
'rnd': '1640181316',
'roomid': '22819508',
'csrf': '131d24bf2b92a3609208ed83758ab8f2',
'csrf_token': '131d24bf2b92a3609208ed83758ab8f2',
}
headers = {
'cookie': '_uuid=CF79473B-0F83-6087-BCB0-23A7E36C479296281infoc; buvid3=8AEBDC64-0CEE-4F6F-9866-B1508FAB2871148805infoc; blackside_state=1; rpdid=|(kmJY|kmu|)0J\'uYJRYkJu|Y; CURRENT_QUALITY=32; buvid_fp=8AEBDC64-0CEE-4F6F-9866-B1508FAB2871148805infoc; video_page_version=v_old_home; sid=abkn3and; i-wanna-go-back=-1; b_ut=5; bp_video_offset_65901796=602085772740229500; LIVE_BUVID=AUTO5916400017585242; CURRENT_BLACKGAP=1; CURRENT_FNVAL=2000; b_lsid=FB21108D7_17DE26BCC89; fingerprint=3c7949ca118951ae1be0b5b37b321306; buvid_fp_plain=556F173C-C5B7-4583-86F9-FD1074EB421D143076infoc; DedeUserID=523606542; DedeUserID__ckMd5=909861ec223d26d8; SESSDATA=cec4dda4%2C1655733287%2Cc5b88*c1; bili_jct=131d24bf2b92a3609208ed83758ab8f2; innersign=0; _dfcaptcha=fbb016616944e9b94331aeb2627c9d3d; PVID=3',
'origin': 'https://live.bi****.com',
'referer': 'https://live.bi****.com/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
}
response = requests.post(url=url, data=data, headers=headers)
print(response.text)
time.sleep(5)
Brothers, support the three companies, I need you to give some motivation~
Follow me for more exciting content! (Free resources are picked up on my left)