I managed to get the WebSocket response in the terminal using the Puppeteer library
import asyncio
from pyppeteer import launch
import time
import pprint
import json
async def test():
args = ['--start-maximized']
browser = await launch(
args=args,
headless=False,
# args=['--no-sandbox'],
# autoClose=False
)
page = await browser.newPage()
await page.goto('https://example.com/')
await page.setViewport({'width': 1920, 'height': 1080})
# create CDP Session
cdp = await page.target.createCDPSession()
await cdp.send('Network.enable')
# Login
await page.type('input[name=login]', 'login')
await page.type('input[name=password]', 'password')
await page.click('button[type=submit]')
time.sleep(2)
# Fill in the request
await page.type('input[name=symbol]', 'ACY')
await page.type('input[name=quantity]', '500')
await page.click('selector')
await page.type('selector', 'Text')
await page.keyboard.press('Enter')
await page.click('button[type=submit]')
# Waiting for the status of "Pending"
await page.waitForSelector('selector, {'timeout': 5000})
def printResponse(response):
pprint.pprint(response)
# Calls printResponse when a websocket is received
cdp.on('Network.webSocketFrameReceived', printResponse)
# Calls printResponse when a websocket is sent
# cdp.on('Network.webSocketFrameSent', printResponse)
await asyncio.sleep(20)
# await page.close()
# await browser.close()
asyncio.get_event_loop().run_until_complete(test_best_location_accept())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…