0

This is my code. I want to get data from webpages. As you can see, there are two var $ = cheerio.load(html). The problem is on the inner one I got "cannot read property 'text' of undefined" error. What is the solution?

request(l1,function(error, resposne, html){
    if(!error){
        var $ = cheerio.load(html);
        $('.list').filter(function(){
            //process
        });
        async.series([
           function(callback){
               request(l2,function(error, response, html){
                  var $ = cheerio.load(html); // error here
                  $('li').filter(function(){

                  });
               });
            callback(null, 'one');
         },
           function(callback){

           callback(null, 'two');
         },
           function(err, results){

         });
    }
ZZZ
  • 1,235
  • 4
  • 14
  • 29
  • There probably is an error, add a `if (error) console.log(error);` before `var $ = cheerio.load(html); `. – Shanoor Feb 17 '16 at 13:33
  • I got this error `{ [Error: socket hang up] code: 'ECONNRESET' }` Why it can happen? – ZZZ Feb 17 '16 at 14:19
  • The connection is reset by the server you're requesting: http://stackoverflow.com/a/17637900/5388620 – Shanoor Feb 17 '16 at 15:33
  • Is there any way to catch the error so the app is not terminated? – ZZZ Feb 17 '16 at 15:40

0 Answers0