TypeError [ERR_INVALID_CALLBACK]:回调必须是一个函数。收到承诺 { <pending> }

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received Promise { <pending> }

我在尝试抓取 prnt.sc 时遇到此错误,我不明白为什么。

我认为 setInterval() 给我带来了问题。

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);

的确,在setInterval中,你应该给出一个函数,而不是执行一个函数。

llamar() 正在执行函数。

试试这个:

setInterval(llamar, 2000);