I'm getting this error while I'm trying to scrape prnt.sc, and I don't understand why.
I think setInterval() is giving me problems.
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received Promise { }
const puppeteer = require("puppeteer");
const select = require('puppeteer-select');
async function llamar() {
const browser = await puppeteer.launch({
headless: true
});
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 6; i++)
text += "https://prnt.sc/" + possible.charAt(Math.floor(Math.random() * possible.length));
console.log(text)
const page = await browser.newPage();
path = Math.random()
await page.goto(text)
const element = await select(page).getElement('button:contains(AGREE)');
await element.click()
await page.screenshot({
path: path + '.jpg'
})
await browser.close();
}
setInterval(llamar(), 2000);
Indeed, in setInterval, you are supposed to give a function, not execute one.
llamar() is executing the function.
Try this:
setInterval(llamar, 2000);