python bilibili直播弹幕

原文:AioWebSocket实现python异步接收B站直播弹幕

python bilibili直播弹幕_第1张图片

import ssl
import websocket
import asyncio
import zlib
import json
import _thread as thread
import time
import requests
class WebsocketClient(object):
    """docstring for WebsocketClient"""

    def __init__(self, address, send_message):
        super(WebsocketClient, self).__init__()
        self.address = address
        self.send_message = send_message

    def on_message(self, ws, message):
        printDM(message)

    def on_error(self, ws, error):
        print("### 报错:", error)

    def on_close(self, ws,x,y):
        print("### 已关闭###")
        print(x,y)

    def on_open(self, ws):
        print("开始连接")

        def run(*args):
            self.ws.send(self.send_message)
            print(self.send_message)
            # self.ws.close()
        hb='00 00 00 10 00 10 00 01  00 00 00 02 00 00 00 01'
        def sendHeartBeat():
            while True:
                time.sleep(

你可能感兴趣的:(python,开发语言)