Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created November 22, 2014 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessioalex/32d4e4fd2039506d8166 to your computer and use it in GitHub Desktop.
Save alessioalex/32d4e4fd2039506d8166 to your computer and use it in GitHub Desktop.
request-hn.js
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