收到这样的错误后可以恢复连接吗
UnhandledPromiseRejectionWarning:
TimeoutError: Navigation Timeout
Exceeded: 1000ms exceeded
例:
let arg = [] //array with urls
await page.goto(...args, {waitUntil: 'load', timeout: 1000 });
还是唯一的办法是设置超时?
最佳答案
如果您想请求args
数组中的所有url而不停止循环(如果其中一个失败的话)。
所以这是解决方案:
const async = require('async'); // npm i --save async
const urls = [... array of urls ...];
const execution = {
total: urls.length,
success: 0,
failed: 0,
results: []
};
async.eachLimit(
urls,
10,
async (url, done) => {
try {
const data = await page.goto(url, {waitUntil: 'load', timeout: 1000});
execution.success++;
execution.results.push({url, data});
}
catch (error) {
execution.failed++;
execution.results.push({url, data: null, error: error.message});
}
finally {
done();
}
},
(errors) => {
console.log('Finished:', execution);
});
关于javascript - Node.js/Puppeteer-导航超时错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53155879/