bilibili傳送彈幕

2021-10-03 04:22:44 字數 3991 閱讀 8033

媳婦兒玩起了bilibili直播,我就順便研究下利用python傳送彈幕,以表支援~,主要思路通過傳送http請求。

1. 查詢http請求

首先登入b站,進入直播間,開啟開發者工具,先在直播間傳送一條彈幕。

可以看到請求的url位址,請求方式是post,以及請求的表單資料:

2. 查詢自己賬號cookie和user-agent資訊

開啟開發者工具,進入個人中心/首頁:

)#獲得當前的時間戳

self.send_data[

'msg'

]= msg

reponse = requests.post(self.send_url, data=self.send_data,cookies=self.cookie,headers=self.header)

return reponse

if __name__ ==

'__main__'

: bullet_screen = bullet_screen(

21912783

) response = bullet_screen.send(

'棒棒噠'

)print

(response)

1. 查詢http請求

開啟開發者工具,重新整理下頁面,找到乙個msg資訊,可以得到路徑和表單資訊:

2. 查詢返回資訊結構

在preview 標籤中可以看到返回了最後10條彈幕:

獲得最近一條彈幕,這樣就可以跟著傳送相同彈幕了

網上有個圖靈機械人,可以實現人機對話,挺有趣,利用它來傳送彈幕內容。

1. 註冊

首先到圖靈機械人註冊,建立機械人,得到乙個32位的key。

2,http請求

請求介面為方式為post,請求引數為如下json格式:

,"inputimage":,

"selfinfo":}

},"userinfo"

:}

3. 返回格式
},

"results":[

},}]

}

4. **
import requests

import json

class

bullet_screen()

:def

__init__

(self, room_id)

: self.room_id = room_id

self.api_key =

''# 填註冊後獲得的32位key

self.user_id =

'9527'

#隨便填

defget_robot_dialogue

(self, msg)

: api_url =

''req =},

'userinfo':}

req = json.dumps(req)

.encode(

'utf8'

) response = requests.post(api_url, data=req, headers=

) response_dic = response.json(

) intent_code = response_dic[

'intent'][

'code'

] results_text = response_dic[

'results'][

0]['values'][

'text'

]return intent_code, results_text

if __name__ ==

'__main__'

: bullet_screen = bullet_screen(

21912783

) code,text = bullet_screen.get_robot_dialogue(

'主播棒棒噠'

)print

(code,text)

現在可以根據最新一條彈幕內容,傳送自動對話的結果了

if __name__ ==

'__main__'

: bullet_screen = bullet_screen(

21912783

) lastmsg = bullet_screen.query(

) code, dialogue = bullet_screen.get_robot_dialogue(lastmsg)

if code ==0:

response = bullet_screen.send(dialogue)

print

(lastmsg,dialogue)

效果如下:

圖靈機械人沒有驗證或者購買的話,只有3次免費試用機會,笑哭

如何在bilibili中查詢彈幕傳送者

總所周知bilibili是沒有辦法直接檢視彈幕的傳送者的,這使得當我們看到一些nt彈幕的時候雖然生氣,卻無可奈何,但是b站是可以遮蔽某個使用者傳送的彈幕的,這說明資料介面裡肯定有使用者資訊,由於最近在學爬蟲,所以我想先找找彈幕介面,分析下裡面的資料。這裡我找到了乙個介面,可以通過aid找到cid 已...

利用觀察者模式實現彈幕傳送效果

html 編寫 lang en charset utf 8 name viewport content width device width,initial scale 1.0 documenttitle head 文字輸入框樣式 input div0 style class div0 src te...

python實現b站直播自動傳送彈幕功能

python 3.6 pycharm import requests import time from tkinter import import random 首先你要登陸b站賬號,然後隨便點選乙個直播間,這裡建議先選擇人氣少的,彈幕少的,這樣方便檢視效果 如上圖所示先開啟開發者工具,定位到xhr...