1 回答

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
您每秒都在啟動(dòng)一個(gè)新的瀏覽器實(shí)例,并且不要關(guān)閉它們。
您的代碼執(zhí)行此操作:
setInterval(() => {
//const instantWind = scrapeAPI();
...
const browser = await puppeteer.launch();
...
}, 1000);
您需要關(guān)閉重用瀏覽器實(shí)例或至少關(guān)閉它們:
const scrapeAPI = async (url) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
var content = await page.content();
innerText = await page.evaluate(() => {
return JSON.parse(document.querySelector("body").innerText);
});
const instantWind = innerText["Instantaneous"];
await browser.close();
return instantWind;
};
添加回答
舉報(bào)