[Python] Nodriver Get Page Status Code and Refresh

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am using nodriver to automate a website login. Sometimes the page will return a 403 error but refreshing the page will solve the issue. I am trying to add logic in my code to do this. Here is my code currently:

    import nodriver as uc
    browser = await uc.start()

    async def myhandler(event: uc.cdp.network.ResponseReceived):
    print(event.response.status)

    browser.main_tab.add_handler(uc.cdp.network.ResponseReceived, myhandler)
    page = await browser.get("https://google.com")


    This returns a bunch of HTTP status codes for every request that was made when trying to access google. How do I check the HTTP status code of the entire page and refresh (with form resubmission) if 403 was returned?

    Continue reading...

Compartilhe esta Página