Skip to content

Instantly share code, notes, and snippets.

@possatti
Created May 15, 2014 20:57
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 possatti/99de2bc1e69ae6d93303 to your computer and use it in GitHub Desktop.
Save possatti/99de2bc1e69ae6d93303 to your computer and use it in GitHub Desktop.
Pega alguns ceps aleatórios de uma página específica.
/**
* Executar usando o PhantomJs.
*/
var page = require('webpage').create();
var url = 'http://www.gerardocumentos.com.br/?pg=gerador-de-cep';
var fs = require('fs');
var fileName = 'ceps.txt';
var ceps = "";
var qtd = 200;
var write = function(name, text) {
try {
fs.write(name, text, 'w');
} catch(e) {
console.log(e);
}
}
page.open(url, function(status) {
for (var i = 0; i < qtd; i++) {
var cep = page.evaluate(function() {
gerarCEP(document.getElementById('campo_cep'));
return document.getElementById('campo_cep').value;
});
ceps += cep + '\n';
console.log('CEP ' + cep);
}
write(fileName, ceps)
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment