Skip to content

Instantly share code, notes, and snippets.

@Cshion
Created June 12, 2016 19:33
Show Gist options
  • Save Cshion/96cf97acf35eb068953e3415ca646546 to your computer and use it in GitHub Desktop.
Save Cshion/96cf97acf35eb068953e3415ca646546 to your computer and use it in GitHub Desktop.
Obtiene informacion de la persona recibiendo como parametro el dni , hasta que no se bajen la pagina web.
var request = require("request");
var cheerio = require("cheerio");
var TARGET = "http://www.votoinformado.pe/voto/miembro_mesa.aspx";
function getPage(dni , callback) {
var data = {
"__EVENTTARGET" : "btnCongrDNI" ,
"__EVENTARGUMENT" : "" ,
"__VIEWSTATE" : "zcBdANVv3exPVBq2FCzvOHX9h711Am07uOAIKAjl0Ql78kOEsoinh5xFeSiCbeCNv5HiI/8cDr+atRB0T6vVJY/TS7vgkxSl7EhaRD+VHRWuen4dwV+vkjN+nTQVORIEFTic9A==" ,
"__VIEWSTATEGENERATOR" : "A8656B09" ,
"__EVENTVALIDATION" : "QdJQGNSuWQL8PBg1OxKT1WE6ku/Ni943XmKPdYzs+/etXwXFwQDG82oViGNviBgmou//cqrIY3o6WYpuh2j2z03CaCtL53OX9BGhjecFYmDdkB/tjFSSJtTHFlKgfNVlkdNSxmx3WAJvlws7VhgtDuNqdZNPbNaVHA6Ed4RnX9RNb7fu" ,
"txtCongrDNI" : dni
};
request.post(TARGET , { form : data } , function (err , response , body) {
if ( err ) {
return callback(err);
} else {
return callback(null , body);
}
});
}
function parse(html , cb) {
try {
var $ = cheerio.load(html);
var table = $("table.tblRespuesta");
var result = {};
result.dni = table.find("#lblDNI").text();
result.nombres = table.find("#lblNombres").text();
result.miembro_mesa = table.find("#lblDNI").text();
result.ubicacion = table.find("#lblUbicacion").text();
result.mesa_sufragio = table.find("#lblMesa").text();
result.local_votacion = table.find("#LblLocal").text();
result.direccion = table.find("#lblDireccion").text();
return cb(null , result);
} catch ( err ) {
return cb(err);
}
}
getPage("06477277" , function (err , html) {
parse(html , function (err , data) {
if ( err ) {
console.error(err);
} else {
console.log(data);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment