Skip to content

Instantly share code, notes, and snippets.

@anthonyringoet
Created December 27, 2012 13:15
Show Gist options
  • Save anthonyringoet/4388324 to your computer and use it in GitHub Desktop.
Save anthonyringoet/4388324 to your computer and use it in GitHub Desktop.
scraping data from the dom with node
var request = require('superagent');
var _ = require('lodash');
var cheerio = require('cheerio');
request.get('http://news.ycombinator.com/', function (res){
var html = res.text,
$ = cheerio.load(html),
index = 1;
var items = $('.title a');
_.each(items, function(item){
if(index < 31){
var result = index + '. ' + $(item).text();
index++;
console.log(result);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment