简体   繁体   English

如何使用 puppeteer 重新加载页面(如果页面不加载)

[英]How to reload a page using puppeteer(if page doesn't load only)

Most of the time I launch my automated bot it stucks at the beginning due to.network issues,so when I reload it,It works.I want my bot to do this if the page doesn't load大多数时候,我启动我的自动机器人时,由于网络问题,它卡在了开头,所以当我重新加载它时,它起作用了。我希望我的机器人在页面未加载时执行此操作

Your page request isn't responded or the response isn't success with status 200 OK.您的页面请求未得到响应或响应未成功,状态为 200 OK。
So maybe you want to get the page requested again if the response isn't OK.因此,如果响应不正确,您可能希望再次请求页面。
These below lines will try to reload the page until it's status is 200 OK.下面这些行将尝试重新加载页面,直到它的状态为 200 OK。

const gotoHome = async () => {
    try {
        let response
        do {
            response = await page.goto('https://www.google.com', {
                timeout: 0,
                waitUntil: 'load'
            })
        } while (response.status() !== 200)
    } catch (error) {
        (async () => await bot.gotoHome())()
    }
}

Please accept my answer as right if this help you.如果对您有帮助,请采纳我的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM