Skip to content

Instantly share code, notes, and snippets.

@adamrights
Created March 20, 2014 20:40
Show Gist options
  • Save adamrights/9673352 to your computer and use it in GitHub Desktop.
Save adamrights/9673352 to your computer and use it in GitHub Desktop.
/*
* Cheerio, A test for crawling anchors on a site.
*/
var request = require('request');
var cheerio = require('cheerio');
var async = require('async');
var jar = request.jar();
request({
followRedirect: true,
uri: process.env.LINKS_FOR || 'https://news.ycombinator.com',
timeout: 10000,
jar: jar
}, function requestCallback(err, res, body) {
var $;
$ = cheerio.load(body);
console.log(body)
console.log('-----------------------------------------')
console.log('---End of HTTP BODY RESPONSE-------------')
console.log('--------Parsed Anchor Links Below--------')
return $('a').each(function() {
return console.log("" + ($(this).text()) + " -> " + ($(this).attr('href')));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment