Skip to content

Instantly share code, notes, and snippets.

@uhtred
Created September 30, 2016 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhtred/f97944d51783e50cb85154c4c80e660d to your computer and use it in GitHub Desktop.
Save uhtred/f97944d51783e50cb85154c4c80e660d to your computer and use it in GitHub Desktop.
Casperjs: cache html
var fs = require('fs');
function savePage(name, content) {
console.log('savePage', name)
fs.write('pages/' + name + '.html', content, 'w');
}
const domain = 'https://algartelecom.com.br'
const pages = [
'/institucional/sustentabilidade/reconhecimentos',
'/institucional/imprensa/noticias',
'/institucional/sustentabilidade/telefone-verde',
'/institucional/sustentabilidade/projetos',
'/institucional/sustentabilidade/politicas',
'/institucional/sustentabilidade/tripe-sustentabilidade',
'/institucional/algar/grupo',
'/institucional/algar/historia',
'/institucional/algar/talentos',
'/institucional/algar/onde-estamos',
'/institucional/algar/escritorios',
'/institucional/algar/premios',
'/AreaCliente/catalogo-planos-servicos'
]
var casper = require('casper').create();
casper.start().eachThen(pages, function(item) {
this.thenOpen(domain + item.data, function(response) {
this.echo(this.getTitle(), response.url)
savePage(response.url.replace(domain, ''), this.getHTML());
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment