梦魇错误-7

时间:2017-03-01 15:34:01

标签: node.js parsing nightmare

美好的一天!我只是想从网站解析一些数据,使用Nightmare,我想解析大约50页,问题是错误 - 7.导航超时。我试图设置更多的时间,但它仍然无效。因此,当我收到此错误时,我可以重新加载或跳过此页面吗?如果我能怎么做呢?这是我试图解决它:

var Nightmare = require('nightmare');
var vo = require('vo');
var nightmare = new Nightmare({ show: false, gotoTimeout: 50000 });

function *start() {
  // Here is my ROOT URL 
  const ROOT = "https:example.com/page/"
  // Looping throw pages
  for (let i = 1; i <= 30; i++) {
    let url =`${ROOT}${i}`
    var links = yield nightmare.goto(url).wait(2000).evaluate(_extractLinks).catch(function (error) {
        console.error('Failed:', error);
        if (error.code == -7) {
            // Here is my try to reload or skip "problem" page - goesn't work
            console.log(error.url);
            // return error.url;
            // var links = nightmare.goto(error.url).wait(2000).evaluate(_extractLinks);
            // // console.log(nightmare.goto(error.url).evaluate(_extractLinks));
            // console.log(links);
        }
    });

    if (links) {
        // Loop throw links that I got on single page
        for (let i = 0; i < links.length; i++) {
            var content = yield nightmare.goto(links[i]).wait(600).evaluate(_extractContent).catch(function (error) {
                console.error('Failed:', error.code);
                if (error.code == -7) {
                    // Here is my try to do something if it is an error
                    console.log(error.url);
                    // return error.url;
                    // nightmare.back().wait(5000).evaluate(_extractContent);
                }
            });

            if (content) {
                console.log(content);
            }
        }
    }

    nightmare.end();
}

function _extractLinks() {
    // Get links from pages
}

function _extractContent() {
    // Get content
}

 vo(start) (function(err) {
    if (err) { return console.log(err); }
    // console.log('finished');
 });

0 个答案:

没有答案