Python pyppeteer Intercept/Capture Network Requests

Viewed 616

Hi I am trying to intercept all the network calls for a given url using pyppeteer,

my code:

import asyncio
from pyppeteer import launch
import pickle

async def interceptResponse(response):
    print("printing response")
    print(response)
    


async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://www.google.com/search?q=sun+flower&rlz=1C1CHBF_enIN963IN963&source=lnms&tbm=isch&sa=X&sqi=2&ved=2ahUKEwjboKfMkoj0AhURppUCHS9hAuMQ_AUoAXoECAIQAw&biw=1920&bih=486&dpr=1')
    new_resutls = page.on('response', 
        lambda response: asyncio.ensure_future(interceptResponse(response)))



asyncio.get_event_loop().run_until_complete(main())

the interceptResponse is getting called only once, (i.e) for the very first network call, for any given url, I would like to capture all the network calls, thanks in advance

1 Answers

try add

await asyncio.sleep(10)

to main function for waiting for other requests

Related