人生苦短,我用Python,所以让我们一起来学习Python吧!
互联网时代,说话没有了限制,于是网络上的“喷子”也是越来越多!
动之以情晓之以理都解决不了这么“喷子”,那么咱们就以其人之道还治其人之身!
环境:
Python3.6+ Windows
模块:
import requests
import time
第一步:获取实时弹幕
1.1 定一个需要送的表单
def post_info_data():
from_data = {
'csrf_token': '',
'roomid': 10185039,
'visit_id': '92cvaa6up88w'}
return from_data
1.2 发送我们已经打包好的数据
def post_data_url(data):
url = 'https://api.live.bilibili.com/ajax/msg'
response = requests.post(url, data=data)
data = response.json()['data']['room']
itemcont = []
for items in data:
itemcont.append(items['text'])
return itemcont[-1]
用一个变量接收打包好的数据
post_data = post_info_data()
while True:
time.sleep(1)
cont = post_data_url(post_data)
print(cont)
第二步: 发送实时弹幕
2.1要找到我们发送弹幕的URL
def post_data_cont():
post_data = {
'color': '16777215',
'csrf_token': '',
'fontsize': 25,
'mode': 1,
'msg': '嗨',
'rnd': '1527404803',
'roomid': '10185039'}
return post_data
向服务器发送信息
def post_url_data(data):
url = 'https://api.live.bilibili.com/msg/send'
cookie = {'Cookie': 'buvid3=9D5AF13F-81C3-44D2-ADBF-7E9EE187FC0A13512infoc; LIVE_BUVID=AUTO5515224216712884; rpdid=kxxkikiqkwdosiipioxpw; finger=c650951b; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1527401127,1527404662; sid=4r7a6x2c; fts=1527401995; DedeUserID=321074467; DedeUserID__ckMd5=17d6f40c8a8668f0; SESSDATA=c30fb9e3%2C1529994023%2Ca56e1407; bili_jct=57cef56872eb3d2938ee9b66edd0bacd; _dfcaptcha=f6bf50348608fde1876dc53faba7f655; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1527404804'}
response = requests.post(url, cookies=cookie, data=data)
if response.status_code == 200:
print(response.json())
pass
form_data = post_data_cont()
post_url_data(form_data)
print(form_data)
第三步: 组合第一步和第二步
3.1步
def post_info_data(roomid):
from_data = {
'csrf_token': '57cef56872eb3d2938ee9b66edd0bacd',
'roomid': roomid,
'visit_id': '92cvaa6up88w'}
return from_data
3.2 发送我们已经打包好的数据
def post_data_url(data):
url = 'https://api.live.bilibili.com/ajax/msg'
response = request.post(url, data=data)
data = response.json()['data']['room']
itemcont = []
for items in data:
itemcont.append(items['text'])
return itemcont[-1]
3.3步
def