Skip to content

Instantly share code, notes, and snippets.

@kimmobrunfeldt
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimmobrunfeldt/10990068 to your computer and use it in GitHub Desktop.
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
// 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