Created
August 18, 2015 02:35
-
-
Save efuquen/f58e550e878d39efa9cc to your computer and use it in GitHub Desktop.
Google News Top Stories Scraper
This file contains hidden or 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.google.com/', function(error, response, body) { | |
if (!error && response.statusCode == 200) { | |
getTopStories(body); | |
} else { | |
console.error(error); | |
console.error('Status Code: ' + response.statusCode); | |
} | |
}); | |
function getTopStories(body) { | |
var $ = cheerio.load(body); | |
var topStories = []; | |
$('#nav-topic-list .topic a').each(function(index, elem) { | |
topStories.push($(elem).text()); | |
}); | |
return topStories; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment