Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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