Created
December 27, 2012 13:15
-
-
Save anthonyringoet/4388324 to your computer and use it in GitHub Desktop.
scraping data from the dom with node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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