3

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

Pyd
  • 6,017
  • 18
  • 52
  • 109
  • Why are you defining `new_results` (you have also typo in there :) )? Simply have `page.on('response', lambda response: asyncio.ensure_future(interceptResponse(response)))` – Ernest Nov 10 '21 at 11:53

1 Answers1

0

try add

await asyncio.sleep(10)

to main function for waiting for other requests

Const
  • 19
  • 3