-
-
Save categulario/e6582d6f8dbf435255c037b228e0555c to your computer and use it in GitHub Desktop.
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
data = [ | |
"44013001", | |
"44042099", | |
"44071001", | |
"44071002", | |
"44072101", | |
"44072102", | |
"44072199", | |
"44072201", | |
"44072299", | |
"44072401", | |
"44072499", | |
"44072901", | |
"44072903", | |
"44072999", | |
"44079101", | |
"44079901", | |
"44079902", | |
"44079904", | |
"44079999", | |
"44081001", | |
"44083999", | |
"44089099", | |
"44092001", | |
"44092099", | |
"44092199", | |
"44092999", | |
"44102999", | |
"44109099", | |
"44121301", | |
"44121399", | |
"44121499", | |
"44121901", | |
"44121999", | |
"44122201", | |
"44122399", | |
"44122999", | |
"44123101", | |
"44123199", | |
"44123201", | |
"44123299", | |
"44123999", | |
"44129201", | |
"44129401", | |
"44129499", | |
"44129901", | |
"44129999", | |
"44140001", | |
"44160002", | |
"44160003", | |
"44160005", | |
"44170099", | |
"44181001", | |
"44182001", | |
"44186001", | |
"44187101", | |
"44187999", | |
"44189099", | |
"44190001", | |
"44201001", | |
"44209099", | |
"44219002", | |
"44219004", | |
"44219099" | |
] |
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 data | |
import re | |
def get_filename_from_cd(cd): | |
""" | |
Get filename from content-disposition | |
""" | |
if not cd: | |
return None | |
fname = re.findall('filename=(.+)', cd) | |
if len(fname) == 0: | |
return None | |
return fname[0] | |
for i in data.data: | |
a = range(2003, 2019) | |
for o in a: | |
url = "http://www.economia-snci.gob.mx/siavi4/frac_mensual.php?fraccion=mensual," + str(o) + "," + i + "&p=excel" | |
r = requests.get(url) | |
filename = 'i{}o{}.xlsx'.format(i, o) | |
print('Will write {}: {}'.format(filename, r.status_code)) | |
open(filename, 'wb').write(r.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment