Created
November 22, 2014 14:05
-
-
Save alessioalex/32d4e4fd2039506d8166 to your computer and use it in GitHub Desktop.
request-hn.js
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('request'); | |
var cheerio = require('cheerio'); | |
request('https://news.ycombinator.com/', function(err, res, body) { | |
if (err) { | |
throw err; | |
} | |
var $ = cheerio.load(body); | |
var results = []; | |
$('.title a').each(function(i, el) { | |
var $el = $(this); | |
results.push({ | |
'text': $el.text(), | |
'href': $el.attr('href') | |
}); | |
}); | |
console.log(results); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment