您好,登錄后才能下訂單哦!
這篇文章主要介紹“Python怎么制作自動發(fā)送彈幕小程序”,在日常操作中,相信很多人在Python怎么制作自動發(fā)送彈幕小程序問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Python怎么制作自動發(fā)送彈幕小程序”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
Python爬取B站彈幕視頻講解
https://www.bilibili.com/video/BV1954y1r7pi/
基本開發(fā)環(huán)境
Python 3.6
Pycharm
相關(guān)模塊使用
import requests import time from tkinter import * import random
1
2
3
4
首先你要登陸B(tài)站賬號,然后隨便點擊一個,直播間,這里建議先選擇人氣少的,彈幕少的,這樣方便查看效果
如上圖所示,先打開開發(fā)者工具,定位到xhr輸入發(fā)送內(nèi)容,點擊發(fā)送,會有一個post請求的send數(shù)據(jù)接口。
所以只需要請求這個數(shù)據(jù)接口即可發(fā)送彈幕。
就是正常的時候爬取數(shù)據(jù),使用requests請求網(wǎng)頁一樣,一般情況大家都是使用的get請求,這里則是需要使用post請求。
所以,只要給請求的時候來一個死循環(huán),那么就可以一直發(fā)送彈幕了,然后再自定義一個彈幕內(nèi)容,讓它每次都是隨機抽選一句話發(fā)送即可。
import requests import time from tkinter import * import random lis_text = ['666', '主播真厲害', '愛了,愛了', '關(guān)注走一走,活到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.bilibili.com/msg/send' data = { 'color': '16777215', 'fontsize': '25', 'mode': '1', 'msg': send_meg, 'rnd': '{}'.format(ti), 'roomid': '{}'.format(roomid), 'bubble': '0', 'csrf_token': '復(fù)制自己的', 'csrf': '復(fù)制自己的', } headers = { 'cookie': '使用你自己的cookie', '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', } a += 1 response = requests.post(url=url, data=data, headers=headers) print(response) text.insert(END, '第{}條彈幕發(fā)送成功'.format(a)) # 文本框滾動 text.see(END) # 更新 text.update() text.insert(END, '發(fā)送內(nèi)容:{}'.format(send_meg)) root = Tk() root.title('B站自動發(fā)送彈幕') root.geometry('560x450+400+200') 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='開始發(fā)送', 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()
到此,關(guān)于“Python怎么制作自動發(fā)送彈幕小程序”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。