0

thanks to this thread i was able to connect to tradingview socket with pyppeteer. But i am not able to work with the response otherwise i block the whole program. I can also not make the function "printResponse" async because then i can not call it with "cdp.on('Network.webSocketFrameReceived', printResponse)" anymore. Can anyone help?

it block at line "response = json.loads(response)"

import asyncio
from pyppeteer import launch
import json

async def main():
    browser = await launch(
        headless=True,
        args=['--no-sandbox'],
        autoClose=False
    )
    page = await browser.newPage()
    await page.goto('https://www.tradingview.com/symbols/BTCUSD/')
    cdp = await page.target.createCDPSession()
    await cdp.send('Network.enable')
    await cdp.send('Page.enable')

    def printResponse(response):
    response = json.loads(response)
        print(response)

    cdp.on('Network.webSocketFrameReceived', printResponse)  # Calls printResponse when a websocket is received
    cdp.on('Network.webSocketFrameSent', printResponse)  # Calls printResponse when a websocket is sent
    await asyncio.sleep(100)


asyncio.get_event_loop().run_until_complete(main())
McMoe
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 31 '22 at 23:39
  • `1.` Your callback function is not properly indented, `2.` The response is already a Python object (`dict`), no need to deserialize. – HTF Aug 01 '22 at 19:52

0 Answers0