Cheerio es un módulo que permite usar jQuery en NodeJS.
Por ejemplo, este script explora un archivo html, retira algunas elementos y hace un reemplazo de tags (es el que uso para generar un html de enlaces a partir de un mapa mental exportado con Freenode):
Por ejemplo, este script explora un archivo html, retira algunas elementos y hace un reemplazo de tags (es el que uso para generar un html de enlaces a partir de un mapa mental exportado con Freenode):
var fs = require('fs');
var cheerio = require('cheerio');
if (!process.argv[2]) {
console.log("Syntax: \nnode prepare_for_blog filename.html");
return;
}
var filename = process.argv[2];
fs.readFile(filename, 'utf8', function(err, html) {
if (err) {
console.log('Error: ', err);
return;
}
var $ = cheerio.load(html);
var $body = $(html).find('body');
$body
.find('ul a').remove().end()
.find('p.info').remove().end()
.find('ul span').removeAttr('style').each(function(i, v) {
var text = $(v).text();
if (text.indexOf('http') >= 0) {
$(v).replaceWith('<a href="https://www.blogger.com/' + text + '">' + text + '</a>');
}
});
console.log($body.html());
});