Last active
August 29, 2015 13:59
-
-
Save kimmobrunfeldt/10990068 to your computer and use it in GitHub Desktop.
Parse http://hwo.azurewebsites.net/, show only subset of teams and write output to file
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
// Install: | |
// npm install lodash request cheerio | |
// Usage: | |
// nodejs hwoteams.js | |
var request = require('request') | |
, cheerio = require('cheerio'); | |
var fs = require('fs'); | |
var _ = require('lodash'); | |
var url = 'http://hwo.azurewebsites.net/'; | |
var futuTeams = ['boris hwo', 'mwaf', 'tammerforce', 'droptable', 'electric sheep', 'last and furious', 'tehoturskat', 'lausanne lakers', 'tj1']; | |
request(url, function(err, resp, body){ | |
$ = cheerio.load(body); | |
$('tr td:nth-child(2)').each(function(i) { | |
var cell = $(this).find('a').html(); | |
if (!cell) { | |
return; | |
} | |
if (!_.contains(futuTeams, cell.toLowerCase())) { | |
$(this).parent('tr').remove(); | |
} else { | |
console.log('Keeping team', cell); | |
} | |
}); | |
fs.writeFile("/var/www/hwo.html", $.html(), function(err) { | |
if(err) { | |
console.log(err); | |
} else { | |
console.log("The file was saved!"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment