Last active
August 29, 2015 14:15
-
-
Save joanfont/e89e46f5a549c7ce879f to your computer and use it in GitHub Desktop.
PSOE's site scrapper to get provinces and towns in Spain
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
import requests | |
import itertools | |
def get_provinces(): | |
data = requests.post('https://afiliate.psoe.es/Resource/GetProvinces') | |
return data.json() | |
def get_municipalities(province): | |
_id = province.get('Id') | |
data = requests.post('https://afiliate.psoe.es/Resource/GetMunicipalities', params = {'idProvince': _id}) | |
province['municipalities'] = data.json() | |
return province | |
if __name__ == '__main__': | |
provinces = itertools.ifilter(lambda x: x.get('code') != 'DES', get_provinces()) | |
municipalities = itertools.imap(get_municipalities, provinces) | |
print list(municipalities) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment