D
D
dfhkjhg2020-07-04 12:43:00
JavaScript
dfhkjhg, 2020-07-04 12:43:00

Why does the fetch request return an error after a while?

There is such a script, with the help of puppeteer I open the site and start throwing a fetch request every 30 seconds

setInterval(async () => await updateFiles(page), 30000)

const updateFiles = async page => {
    const data = await page.evaluate(async () => {
        const request = await fetch(`https://site.com`)
        const data = await request.text()

        return data
    })

    global.$ = cheerio.load(data, { decodeEntities: true })
    const results = handler(data);
    console.log(results.length)
    await db.loadFiles(results, b)
}


For a while everything works fine, but then the fetch request stops returning anything (like a 503 error)
How can I fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-07-04
@Aetae

5xx errors - server errors.
Specifically 503 - Service Temporarily Unavailable - the service is temporarily unavailable.
The server sends you to hell. Most likely there is a protection against frequent repetitive requests. Either the server crashes, but that's unlikely.
You can try to randomize the query frequency and change the headers and user agent. But he doesn't know what will help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question