Last active
December 31, 2015 02:09
-
-
Save mhkeller/7919308 to your computer and use it in GitHub Desktop.
Node scraper with require.js and cheerio.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'), | |
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