这篇文章主要讲解了“Python怎么实现直播弹幕自动发送功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python怎么实现直播弹幕自动发送功能”吧!
先打开一个直播间
按F12打开开发者工具
发送弹幕666
在send里找到我们所需的链接
需要加上headers和data
import requests url = 'https://api.live.bilibili.com/msg/send' data = { 'bubble': '0', 'msg': '666666', 'color': '16777215', 'mode': '1', 'fontsize': '25', 'rnd': '1646460756', 'roomid': '545068', 'csrf': 'a121a39614a5131b700e07334c3e2f2e', 'csrf_token': 'a121a39614a5131b700e07334c3e2f2e', } headers = { 'cookie': 'buvid3 = B68B2187 - 4C3E - 4466 - A896 - FBF9B292099B190963infoc;LIVE_BUVID = AUTO4115757254257055;rpdid = | (umu | ulY)JJ0J\'ul~l~klRJ); Hm_lvt_ff57561a8cad2056ebeb8790418f7c80=1617598823; dy_spec_agreed=1; fingerprint_s=72d878d168cc36c3e67084f9ab1b28bf; kfcFrom=SIXIN; video_page_version=v_old_home; _uuid=838215105-B7C3-D1D3-8866-D41AAC22362C56007infoc; CURRENT_BLACKGAP=0; blackside_state=0; buvid_fp_plain=undefined; buvid4=475D6CE2-93EF-3AD0-EBCD-C528FD289A2218219-022012015-hoqbRiv5RkzgH6uKZsx6eQ%3D%3D; i-wanna-go-back=-1; fingerprint3=282838a0bbd808eda8dde1558fccc94c; CURRENT_QUALITY=80; bp_video_offset_296816901=629971213059358700; sid=jtva59n5; fingerprint=416f0a37448a1faf863af4402998db67; DedeUserID=523606542; DedeUserID__ckMd5=909861ec223d26d8; SESSDATA=c666f798%2C1661245310%2C91227*21; bili_jct=ac2dd02c170854b995d5a6a601d973ea; buvid_fp=416f0a37448a1faf863af4402998db67; b_ut=5; bp_t_offset_523606542=630736739432923172; bp_video_offset_523606542=631076973870841894; innersign=0; b_lsid=B77BFA43_17F2FE6E01B; CURRENT_FNVAL=80; _dfcaptcha=fa1b3951be7c6744827b636f6c4935c9; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1645778002; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1645778002; PVID=7', 'origin': 'https://live.bilibili.com', 'referer': 'https://live.bilibili.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', response = requests.post(url=url, data=data, headers=headers) print(response.status_code)
import random import time lis_text = ['666', '主播真厉害', '爱了,爱了', '关注走一走,活到99', '牛逼!!!', '秀儿,是你吗?'] while True: time.sleep(2) send_meg = random.choice(lis_text) roomid = entry.get() ti = int(time.time()) url = 'https://api.live.bilibili.com/msg/send' data = { 'color': '16777215', 'fontsize': '25', 'mode': '1', 'msg': send_meg, 'rnd': '{}'.format(ti), 'roomid': '{}'.format(roomid), 'bubble': '0', 'csrf': 'ac2dd02c170854b995d5a6a601d973ea', 'csrf_token': 'ac2dd02c170854b995d5a6a601d973ea', }
做个交互界面
from tkinter import * root = Tk() root.title('B站自动发送弹幕') root.geometry('560x450+400+200') label = Label(root, text='请输入房间号:', 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) root.mainloop()
将前面发送弹幕的代码设成函数,再调用
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)
感谢各位的阅读,以上就是“Python怎么实现直播弹幕自动发送功能”的内容了,经过本文的学习后,相信大家对Python怎么实现直播弹幕自动发送功能这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。