Skip to content

Instantly share code, notes, and snippets.

@quagliero
Created February 4, 2015 13:09
Show Gist options
  • Save quagliero/fdf51e3299768fa2f818 to your computer and use it in GitHub Desktop.
Save quagliero/fdf51e3299768fa2f818 to your computer and use it in GitHub Desktop.
NFL Fantasy League History Almanac scrape
var req = require('request');
var cheerio = require('cheerio');
req('http://fantasy.nfl.com/league/874089/history', function (error, response, body) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(body);
console.log('\n');
$('[class*="history-champ"]').each(function (i, e) {
var $row = $(e);
var year = $row.find('.historySeason').text();
var team = $row.find('.historyTeam .teamName').text();
console.log(year + ' Champion: ' + team);
});
console.log('\n');
$('[class*="history-btw"]').each(function (i, e) {
var $row = $(e);
var year = $row.find('.historySeason').text();
var week = $row.find('.historyWeek').text();
var team = $row.find('.historyTeam .teamName').text();
var points = $row.find('.historyPts').text();
console.log(year + ' Weekly Points Winner: ' + team + ' with ' + points + ' points in week ' + week);
});
console.log('\n');
$('[class*="history-bpw"]').each(function (i, e) {
var $row = $(e);
var year = $row.find('.historySeason').text();
var week = $row.find('.historyWeek').text();
var team = $row.find('.historyTeam .teamName').text();
var player = $row.find('.playerNameAndInfo .playerName').text();
var posTeam = $row.find('.playerNameAndInfo em').text();
var points = $row.find('.historyPts').text();
console.log(year + ' Weekly Player Points Winner: ' + team + ' with ' + player + ' (' + posTeam + ') with ' + points + ' points in week ' + week);
});
console.log('\n');
$('[class*="history-bts"]').each(function (i, e) {
var $row = $(e);
var year = $row.find('.historySeason').text();
var team = $row.find('.historyTeam .teamName').text();
var points = $row.find('.historyPts').text();
console.log(year + ' Season Points Winner: ' + team + ' with ' + points + ' points');
});
console.log('\n');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment