gpt4 book ai didi

javascript - Nodejs/puppeteer - 导航超时错误

转载 作者:行者123 更新时间:2023-11-30 14:18:26 25 4
gpt4 key购买 nike

出现这样的错误后,我可以恢复连接吗

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 - Nodejs/puppeteer - 导航超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53155879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com