Skip to content

Instantly share code, notes, and snippets.

@pkpp1233
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save pkpp1233/044409f3ef6df7e37128 to your computer and use it in GitHub Desktop.

Select an option

Save pkpp1233/044409f3ef6df7e37128 to your computer and use it in GitHub Desktop.
Pull ESPN Headlines Function

Choose a sport and get the headlines.

Sports:
"" = all
"nhl" = NHL
"mlb" = MLB
"nba" = NBA
"college-football" = College football
"mens-college-basketball" = Mens college basketball
"racing/nascar" = NASCAR

var request = require('request');
var cheerio = require('cheerio');
var sport = "nhl";
request('http://www.espn.com/' + sport, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
var headlines = []
$('.headlines li').each(function(i, elem){
headlines.push($(this).text());
})
console.log(JSON.stringify(headlines));
} else {
console.log("Could not find espn headlines.");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment