Tuesday 23 May 2017

Async map with Cheerio

I get an issue using Async and Cheerio.

My code :

var request    = require('request'),
    cheerio    = require('cheerio'),
    _          = require('lodash'),
    sitesJson  = require('./websites.json'),
    Sequelize  = require('sequelize'),
    asyncFn    = require('async');

asyncFn.map(sitesJson.sites, function(site) {

  request(site.url, function (error, response, body) {

    $ = cheerio.load(body);

    $(site.eventsQuery).each( function() {

      var event = {
        title : eval(site.titleQuery),
        description : eval(site.descriptionQuery),
        thumbnail : eval(site.thumbnailQuery),
        lat : eval(site.latQuery),
        lng : eval(site.lngQuery)
      };

      console.log(event); // not null

      return event;
    });

  });

}, function(err, results) {

  console.log(results); // null

});

Issue : I'm not able to get the events... While in the map function the events objects are not null.



via tonymx227

No comments:

Post a Comment