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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| import requests import time import random import pymysql
connection = pymysql.connect( host="localhost", user="root", passwd="", database="danmaku", )
cursor = connection.cursor() sql = "SELECT COUNT(*) FROM test"
cursor.execute(sql) table_length = cursor.fetchone()[0]
sql1 = "select comment from test where id= %s"
url = "https://api.live.bilibili.com/msg/send"
salt_data1 = { 'jumpfrom': '', 'csrf': '', 'csrf_token': '', }
salt_data2 = { 'jumpfrom': '', 'csrf': '', 'csrf_token': '', }
headers1 = { 'cookie':"", 'Origin': 'https://live.bilibili.com', 'Referer': "", "user-agent":"" }
headers2 = { 'cookie':"", 'Origin': 'https://live.bilibili.com', 'Referer': "", "user-agent":""
salt_list = [salt_data1, salt_data2] header_list = [headers1, headers2]
while True: time.sleep(2) timestamp = int(time.time())
cursor.execute(sql1, random.randint(1, table_length)) random_comment = cursor.fetchone()[0]
com_data = { 'bubble': '0', 'msg': '{}'.format(random_comment), 'color': '16777215', 'mode': '1', 'room_type': '0', 'fontsize': '25', 'rnd': '{}'.format(timestamp), 'roomid': '13845655', }
randint = random.randint(0, 1)
select_salt = salt_list[randint] select_header = header_list[randint]
data = {}
for data_dict in [com_data, select_salt]: data.update(data_dict)
response = requests.post(url=url, data=data, headers=select_header)
if response.status_code == 200: print("消息发送成功!") else: print(f"消息发送失败,状态码:{response.status_code}") print(response.text)
|