Skip to main content

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 [ ] (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. [ ]

Note: There's a ton of information at #Freesoftwareando, in fact at the beggining the parsers used his municipalities 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, 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 municipalities and each and the provinces.

The next step is to prepare, 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 spreadsheets (a table for province, municipality, name, surname, list, position.