Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created January 20, 2013 20:47
Show Gist options
  • Save geNAZt/4581624 to your computer and use it in GitHub Desktop.
Save geNAZt/4581624 to your computer and use it in GitHub Desktop.
var async = require('async'),
urlIDs = [1, 2, 3],
httprequest = require('request'),
cheerio = require('cheerio');
async.reduce(urlIDs, [], function (results, item, reduceCallback) {
"use strict";
console.log("I've iterated " + item + "x");
process.nextTick(function () {
var moreStuff = [];
httprequest("http://www.homerj.de/index.php?show=user&user=" + item, function (error, response, body) {
var $ = cheerio.load(body),
count = 0;
async.waterfall([
function (callback) {
$('a').each(function (i, elem) {
count += 1;
});
callback(null, count);
},
function (count2, callback) {
$('a').each(function (i, elem) {
moreStuff.push($(this).text());
if (i === count2 - 1) {
callback(null, moreStuff);
}
});
}],
function (err, result) {
results.push(result);
reduceCallback(null, results);
});
});
});
}, function (err, results) {
"use strict";
console.log(results);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment