我如何才能在执行 puppeteer 的多个任务时只使用 1 个浏览器实例?我正在抓取的网站正在检测浏览器实例的创建,即使在等待 browser.close() 之后也是如此。因此,如果我始终打开浏览器,我就可以绕过它。
示例场景:
(async() => {
const browser = await puppeteer.launch({headless: true}); //
// Have this only run once ^^^^
// Command gets run, it should not make a new browser and instead go
// to make a new page
// VVVVVVVV
const page = await browser.newPage();
await page.goto(args[1]) // Go to the url the user specified
// do some stuff
await page.close();
//repeat from browser.newPage();
})();
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
puppeteer ×1