Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created January 20, 2013 13:04
Show Gist options
  • Save geNAZt/4578504 to your computer and use it in GitHub Desktop.
Save geNAZt/4578504 to your computer and use it in GitHub Desktop.
var req = require('request'),
cheerio = require('cheerio'),
async = require('async'),
urls = ["http://google.com/", "http://test.de/", "http://bild.de/"];
function crawlUrl(url, callback) {
"use strict";
var array = [];
req(url, function (error, response, body) {
var $ = cheerio.load(body);
$('strong').length;
$('strong').each(function (i, item) {
array.push($(this).text());
if (i === $('strong').length) {
callback(null, array);
}
});
});
}
async.map(urls, crawlUrl, function (err, results) {
"use strict";
console.log(results);
// results is now an array of the array for each url
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment