Git Product home page Git Product logo

dinescrap's Introduction

dinescrap

Scrapper del sitio de la Dirección Nacional Electoral. Contiene pre-candidatos a diputados nacionales, senadores nacionales y parlamentarios mercosur de todas las provincias para las PASO 2015.

Descargar datos en CSV: https://github.com/YoQuieroSaber/dinescrap/tree/master/salida

Los datos están basados en información de dominio público. Si se reutilizan solicitamos que nos informen para evitar duplicar esfuerzos.

Fuente: http://www.elecciones.gov.ar/articulo_sub_sub.php?secc=2&sub_secc=8&sub_sub_secc=63

Requerimientos

Para repetir manualmente este proceso es necesario un sistema linux con los siguientes paquetes instalados:

  • pdftotext
  • nodejs
  • npm

Pasos

  1. El primer paso para que funcione este scrapper es bajarse todos los PDFs.

  2. Correr los scripts (ver más abajo)


Primero vamos a bajar los de las 8 secciones, que son los que tienen las candidaturas para diputados provinciales. Bajamos primero los HTMLs de cada sección:

wget "http://www.elecciones.gov.ar/articulo_sub_sub.php?secc=2&sub_secc=8&sub_sub_secc=63"

Luego filtramos sólo las líneas que tengan URLs:

cat * | sed -n '/href=\"\//p' > urls.txt

En el archivo urls.txt nos van a quedar todas las líneas con links a PDFs, pero hay que borrar todo el HTML y agregarle la primer parte de la URL.

Eso se hace con las funciones de búsqueda y reemplazar de un editor de texto hasta que quedamos con las URLs completas, les ponemos comillas al principio y al final y generamos este comando:

wget "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/PRESIDENTE%20Y%20VICEPRESIDENTE.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/PARLAMENTARIO%20MERCOSUR%20DISTRITO%20NACIONAL(1).pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/BUENOS%20AIRES.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CORRIENTES.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/MENDOZA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SAN%20LUIS.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CAPITAL%20FEDERAL.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/ENTRE%20RIOS.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/MISIONES.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SANTA%20CRUZ.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CATAMARCA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/FORMOSA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/NEUQUEN.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SANTA%20FE.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CHACO.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/JUJUY.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/RIO%20NEGRO.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SANTIAGO%20DEL%20ESTERO.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CHUBUT.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/LA%20PAMPA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SALTA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/TIERRA%20DEL%20FUEGO.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/CORDOBA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/LA%20RIOJA.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SAN%20JUAN.pdf" "http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/TUCUMAN.pdf"

Esto nos permite descargar los PDFs, y luego hay que convertir los PDFs a texto usando pdftotext

ls *.pdf | while read x y ; do pdftotext -layout $x text-$x.txt;  done
ls *.pdf | while read x y ; do pdftotext -layout $x $y text-$x $i.txt;  done

Ahora sólo queda correr el script para convertirlo en CSV


Para correr los scripts

npm install
cd app
node formatearDine.js

Esto genera archivos en la carpeta ./salida/

dinescrap's People

Contributors

martinszy avatar

Watchers

James Cloos avatar  avatar

Forkers

nullpo

dinescrap's Issues

Algunos candidatos tiene mal el cargo

Ejemplo, en el CSV de Santa Fe:
https://github.com/YoQuieroSaber/dinescrap/blob/master/salida/SANTA%20FE.csv

"SANTA FE PARLAMENTARIO MERCOSUR DISTRITO REGIONAL SUPLENTE TELPUK, MARIA LUJAN 2"

Pero en el PDF
http://www.elecciones.gov.ar/admin/ckfinder/userfiles/files/SANTA%20FE.pdf

"503 ALIANZA COMPROMISO FEDERAL, LISTA: 2B DESARROLLO AGRO INDUSTRIAL. SENADOR NACIONAL TITULAR

  1. GRANELLI, JUAN JAVIER
  2. TELPUK, MARIA LUJAN"

Está mal el cargo, que debe ser senador y es parlamentario. Lo tomó del cargo anteiror que si era parlamentario.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.