Javascript Nodejs/puppeter-导航超时错误

Javascript Nodejs/puppeter-导航超时错误,javascript,node.js,puppeteer,Javascript,Node.js,Puppeteer,在收到这样的错误后,我可以恢复连接吗 UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 1000ms exceeded 例如: let arg = [] //array with urls await page.goto(...args, {waitUntil: 'load', timeout: 1000 }); 或者唯一的解决办法是设置超时?我相信您的问题来自您提供

在收到这样的错误后,我可以恢复连接吗

UnhandledPromiseRejectionWarning:    
TimeoutError: Navigation Timeout    
Exceeded: 1000ms exceeded
例如:

 let arg = [] //array with urls
 await page.goto(...args, {waitUntil: 'load', timeout: 1000 }); 

或者唯一的解决办法是设置超时?

我相信您的问题来自您提供给
木偶演员
转到
方法的参数:


当您调用
goto
时,它需要一个
字符串而不是
数组来回答原始问题:

否,在
page.goto()函数超时后无法恢复连接。您只能处理该异常,或许可以重试

另一方面,如果您试图完成的是加载一个页面

我建议对代码进行两项更改:

第一名:

page.goto()
不接受
数组
对象
作为第一个参数,它必须是单数字符串,例如:

page.goto('https://www.google.com)

秒:

除非加载的页面非常简单,否则1000毫秒的
超时时间就太低了。木偶演员的默认值为30000毫秒,因此我建议使用该值或将超时设置为至少5000毫秒:

page.goto('https://www.google.com“,{timeout:5000})

也不需要使用
{waitUntil:'load'}
,因为这是默认值


希望这对您有所帮助。

如果您想请求
args
数组中的所有URL,并且在其中一个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);
  });