python模拟发送websocket请求的模块
pip3 install websocket-client
基于 websocket-client
的示例代码
from websocket import WebSocketAppdef on_open(ws):print("on_open", ws)def on_message(ws, message):# 回调函数,直接接收到xx的弹幕信息print("on_message", message)def on_error(ws, message):print("on_error", ws, message)def on_close(ws, **args, **kwargs):passdef run():# 向xx发送web请求链接ws = WebSocketApp(url = "xxx",header={},cookie="",on_open=on_open,on_message=on_message,on_error=on_error,on_close=on_close)ws.run_forever()if __name__ == '__main__':run()