最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

selenium python handle message websocket - Stack Overflow

programmeradmin4浏览0评论

my code:

def get_ws_messages(driver):
    ws_messages = []
    sleep(2)
    driver.execute_cdp_cmd("Network.enable", {})
    logs = driver.get_log("performance")
    for entry in logs:
        try:
            log_data = json.loads(entry["message"])["message"]
            if log_data["method"] == "Network.webSocketFrameReceived":
                message = log_data["params"]["response"]["payloadData"]
                ws_messages.append(message)
                print("WebSocket Message:", message)
        except (KeyError, json.JSONDecodeError):
            continue

    return ws_messages

I use selenium on python to write auto scripts. My project has a section that needs to handle websocket messages. I use selenium's cdp to handle websocket messages, but it only returns a part and does not return the full websocket message. What should I do to get the full websocket message?

发布评论

评论列表(0)

  1. 暂无评论