You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can simply do this with sync api but I have no idea how to with async api;
I've tried code like:
def check(response):
body_text = response.text()
# check if it is the response I need
async def foo():
page = await browser.new_page()
async with page.expect_response(url_or_predicate=check) as res:
#other job
but only got error said coroutine returned by response.text() needs await;
if I change check to async function I got another error said check needs await.
what is the correct way accessing response's body with async api?
The text was updated successfully, but these errors were encountered:
Based on the impl, it looks like the predicate cannot be an async function today.
As a workaround, you can create and await a Future instead of using the built in page.expect_response for this case:
# set up your listener and futurematched_response_fut=asyncio.Future()
asyncdefis_matching(response: Response):
body=awaitresponse.text()
ifbody=="some text you're looking for":
matched_response_fut.set_result(response)
page.on("response", is_matching)
# take your action(s) that will actually trigger the response# e.g. navigation, clicking, etc.# …# await and use your matched responseresponse=awaitmatched_response_fut
Your question
I can simply do this with sync api but I have no idea how to with async api;
I've tried code like:
but only got error said coroutine returned by response.text() needs await;
if I change check to async function I got another error said check needs await.
what is the correct way accessing response's body with async api?
The text was updated successfully, but these errors were encountered: