Obtaining the spanish town concilor database

I found out via javibc that there's a treasury department portal with data about all spanish town concilors [ http://ssweb.mpt.es/portalEELL/con­sul­ta_al­caldes ] (you have to enter twice, first to get the cookie and get redirected to the homepage and a second to access the form :P), and after several headcaches here it is the parser and the database. [ cargos.zip ]

Note: There's a ton of in­for­ma­tion at #Freesoft­ware­an­do, in fact at the beggining the parsers used his mu­nic­i­pal­i­ties database but now they generate another one to avoid use something outside the standard python libraries.

To parse it again, first we have to prepare and launch get_provincias.py, make it ready the cookie string have to be edited (line 20) to fit the ones the web has assigned you, after launching the script it'll prepare a database with the mu­nic­i­pal­i­ties and each and the provinces.

The next step is to prepare get_cargos.py, again the cookie string (line 8) has to be edited and this time also we have to set the csrf_token (line 128) which can be found in the site looking for this:

<input type="hidden" name="consulta_alcalde[_csrf_token]"
    value="717f8d1f38ba8e586a2fcbc5ca2b840c" id="consulta_alcalde__csrf_token" />

The obtained database would be something like this [ cargos.sqlite3.gz ] ( whitout the .gz :P)

Also available in other formats

  • sqlite2

  • CSV useful for the spread­sheets (a table for province, mu­nic­i­pal­i­ty, name, surname, list, position.