https://www.cnblogs.com/feiyueNotes/p/8097632.html
Python自动发射弹幕,弹幕护体
- 环境: Python3+Windows
- 开发工具: PyCharm
学习效果:
1. 学会使用Python刷弹幕
2. 配置INI文件信息
3. 掌握网络请求知识
4. 解浏览器开发者工具
5. 时间模块的使用
6.爬虫的基本知识
https://www.bilibili.com/video/av11149694/
手动发送两条弹幕,抓包查看表单数据,找出不同的参数,注意相应修改
用户登录信息,消息头-cookie
脚本如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#coding=utf-8import requests,time,random
import configparser #配置文件信息
target = configparser.ConfigParser() #文件对象
target.read(r'D:\t.ini',encoding='utf-8') #读取文件<br>
while True:
#message = target['我的弹幕'][str(random.randint(1,8))]
message = target.get('我的弹幕',str(random.randint(1,8)))
url = 'https://interface.bilibili.com/dmpost?cid=18447007&aid=11149694&pid=1&ct=1'
cookie = {'cookie':''}
form = {'fontsize':'25',
'pool':'0',
'mode':'1',
'color':'16777215',
'rnd':str(time.time()*1000000),#时间戳
'message':message,
'playTime':'0.08',
'cid':'18447007',
'date':time.strftime('%Y-%m-%d+%H:%M:%S',time.localtime(time.time())),
#'date':time.strftime('%Y-%m-%d+%X', time.localtime(time.time())),
'csrf':'3915a57109e4abe13dc752254df4bc35'
}
requests.post(url,cookies=cookie,data=form)
# requests.request('POST',url, data=form,cookies=cookie)
print(message)
time.sleep(5)
|
配置文件如下: