Skip to content

Instantly share code, notes, and snippets.

@arisolt
Last active December 11, 2015 09:38
Show Gist options
  • Save arisolt/4581300 to your computer and use it in GitHub Desktop.
Save arisolt/4581300 to your computer and use it in GitHub Desktop.
var async = require('async'),
array1 = [1, 2, 3],
array2 = ['stuff'],
cheerio = ['cheerio'],
httprequest = require('request');
async.reduce(array1, array2, function (array2, item, callback) {
console.log("I've iterated " + item + "x");
callback (array2.push(
function () {console.log("aa");
var moreStuff = [];
return httprequest("http://dummywebsite.com?id=" + item, function () {
var $ = cheerio.load(body);
var count = 0;
return async.waterfall([
function (callback) {
$('strong').each(function(i, elem) {
count++;
});
callback(null, count);
},
function (count2, callback) {
$('strong').each(function(i, elem) {
moreStuff.push($(this).text());
if (i == count2 - 1) {
callback(null, moreStuff);
};
});
}],
function (err, result) {
return result;
});
});
}
));
}, function (err, results){console.log(err);}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment