爬虫 websocket

基础使用

pip install websocket-client

查看网站

import websocket
import json

if __name__ == '__main__':
    ws = websocket.create_connection('wss://ws.bitforex.com/mkapi/coinGroup1/ws', timeout=10)
    ws.send(
        '[{"type": "subHq", "event": "trade", "param": {"businessType": "coin-usdt-btc", "dType": 0, "size": 100}}]')  # 订阅交易数据
    while True:
        content = ws.recv()
        for data in json.loads(content).get("data"):
            print(data)
    ws.close()
原文地址:https://www.cnblogs.com/iFanLiwei/p/12846677.html