您好,登錄后才能下訂單哦!
這篇文章主要講解了“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。