Created
September 30, 2016 22:26
-
-
Save uhtred/f97944d51783e50cb85154c4c80e660d to your computer and use it in GitHub Desktop.
Casperjs: cache html
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
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