Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Last active December 31, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhkeller/7919308 to your computer and use it in GitHub Desktop.
Save mhkeller/7919308 to your computer and use it in GitHub Desktop.
Node scraper with require.js and cheerio.js
var request = require('request'),
cheerio = require('cheerio');
function scraper(url, cb){
request(url, function (err, response, body) {
if (err) {throw err};
// return the err, the html to be scraped
cb(err, cheerio.load(body));
})
}
scraper('http://america.aljazeera.com', function(err, $){
var headline = $('h1.topStories-headline a').html();
console.log(headline);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment