Created
May 15, 2014 20:57
-
-
Save possatti/99de2bc1e69ae6d93303 to your computer and use it in GitHub Desktop.
Pega alguns ceps aleatórios de uma página específica.
This file contains 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
/** | |
* 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