【发布时间】:2019-01-08 10:05:25
【问题描述】:
我想将 for 循环变量传递给 puppeteer 中的 page.evaluate,以获取画廊的所有量具。但它不起作用。它总是报告UnhandledPromiseRejectionWarning: Error: Evaluation failed。
以下是我的代码示例:
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch({executablePath:'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'});
const page = await browser.newPage();
await page.goto('D:\\Code Workplace\\Javascripts\\TurnPage\\index.html', {waitUntil: 'networkidle2'});
for (let index = 0; index < 4; index++) {
await page.evaluateHandle((index) => {
$('.flipbook').turn('page', index);
}, index);
}
await sleep(300);
await page.emulateMedia('print');
await page.pdf({path: 'hn.pdf', format: 'A4', printBackground: true});
await browser.close();
})();
所以我需要帮助将循环变量传递给变量。以前有人遇到过这个问题吗?感谢您的热心帮助。
【问题讨论】: