Last active
November 25, 2019 18:17
-
-
Save glarrain/4111796 to your computer and use it in GitHub Desktop.
Administrative divisions of Chile: Comunas, Provincias, Regiones
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
{ | |
"Región de los Ríos": [ | |
"Panguipulli", | |
"Corral", | |
"Paillaco", | |
"La Unión", | |
"Los Lagos", | |
"Río Bueno", | |
"Futrono", | |
"Lago Ranco", | |
"Máfil", | |
"Valdivia", | |
"Lanco", | |
"Mariquina" | |
], | |
"Región del Maule": [ | |
"San Rafael", | |
"Hualañé", | |
"Curepto", | |
"Empedrado", | |
"Constitución", | |
"Longaví", | |
"San Clemente", | |
"Romeral", | |
"Chanco", | |
"Villa Alegre", | |
"Pencahue", | |
"Molina", | |
"Talca", | |
"Parral", | |
"Rauco", | |
"Cauquenes", | |
"Retiro", | |
"Río Claro", | |
"Sagrada Familia", | |
"Yerbas Buenas", | |
"San Javier", | |
"Maule", | |
"Teno", | |
"Pelluhue", | |
"Colbún", | |
"Licantén", | |
"Linares", | |
"Curicó", | |
"Pelarco", | |
"Vichuquén" | |
], | |
"Región del Libertador General Bernardo O'Higgins": [ | |
"San Vicente", | |
"Graneros", | |
"Lolol", | |
"Malloa", | |
"Palmilla", | |
"Litueche", | |
"Rengo", | |
"Las Cabras", | |
"Peralillo", | |
"Nancagua", | |
"Santa Cruz", | |
"Rancagua", | |
"Marchihue", | |
"Doñihue", | |
"Coinco", | |
"Mostazal", | |
"Paredones", | |
"Placilla", | |
"Navidad", | |
"La Estrella", | |
"Chimbarongo", | |
"Olivar", | |
"Pumanque", | |
"Requínoa", | |
"Pichilemu", | |
"Machalí", | |
"San Fernando", | |
"Chépica", | |
"Peumo", | |
"Pichidegua", | |
"Codegua", | |
"Coltauco", | |
"Quinta de Tilcoco" | |
], | |
"Región de Atacama": [ | |
"Copiapó", | |
"Chañaral", | |
"Diego de Almagro", | |
"Vallenar", | |
"Caldera", | |
"Alto del Carmen", | |
"Freirina", | |
"Huasco", | |
"Tierra Amarilla" | |
], | |
"Región de Antofagasta": [ | |
"Ollagüe", | |
"Taltal", | |
"Sierra Gorda", | |
"San Pedro de Atacama", | |
"Antofagasta", | |
"María Elena", | |
"Mejillones", | |
"Tocopilla", | |
"Calama" | |
], | |
"Región de Magallanes y de la Antártica Chilena": [ | |
"Río Verde", | |
"Timaukel", | |
"Torres del Paine", | |
"Porvenir", | |
"Primavera", | |
"San Gregorio", | |
"Punta Arenas", | |
"Cabo de Hornos (Ex-Navarino)", | |
"Natales", | |
"Antártica", | |
"Laguna Blanca" | |
], | |
"Región de Arica y Parinacota": [ | |
"Putre", | |
"Camarones", | |
"Arica", | |
"General Lagos" | |
], | |
"Región de Valparaíso": [ | |
"Olmué", | |
"Valparaíso", | |
"Catemu", | |
"San Esteban", | |
"Santo Domingo", | |
"Villa Alemana", | |
"Casablanca", | |
"Nogales", | |
"Algarrobo", | |
"Juan Fernández", | |
"Cabildo", | |
"Quintero", | |
"Calle Larga", | |
"Quillota", | |
"Panquehue", | |
"Concón", | |
"Llaillay", | |
"Hijuelas", | |
"Isla de Pascua", | |
"Santa María", | |
"San Felipe", | |
"Los Andes", | |
"Zapallar", | |
"San Antonio", | |
"Rinconada", | |
"Cartagena", | |
"El Quisco", | |
"El Tabo", | |
"Quilpué", | |
"Puchuncaví", | |
"Papudo", | |
"Viña del Mar", | |
"Petorca", | |
"La Ligua", | |
"Putaendo", | |
"La Cruz", | |
"Calera", | |
"Limache" | |
], | |
"Región de la Araucanía": [ | |
"Melipeuco", | |
"Curarrehue", | |
"Traiguén", | |
"Pitrufquén", | |
"Lautaro", | |
"Teodoro Schmidt", | |
"Temuco", | |
"Gorbea", | |
"Angol", | |
"Nueva Imperial", | |
"Toltén", | |
"Los Sauces", | |
"Saavedra", | |
"Purén", | |
"Galvarino", | |
"Freire", | |
"Ercilla", | |
"Curacautín", | |
"Loncoche", | |
"Lumaco", | |
"Cunco", | |
"Pucón", | |
"Padre Las Casas", | |
"Carahue", | |
"Victoria", | |
"Lonquimay", | |
"Villarrica", | |
"Vilcún", | |
"Cholchol", | |
"Collipulli", | |
"Perquenco", | |
"Renaico" | |
], | |
"Región del Biobío": [ | |
"Quilleco", | |
"Cabrero", | |
"Ñiquén", | |
"Coronel", | |
"Laja", | |
"Concepción", | |
"Chillán", | |
"Chiguayante", | |
"Coelemu", | |
"Alto Biobío", | |
"Ránquil", | |
"Los Angeles", | |
"Coihueco", | |
"Los Alamos", | |
"Arauco", | |
"Ninhue", | |
"San Rosendo", | |
"Quillón", | |
"Chillán Viejo", | |
"Nacimiento", | |
"Cañete", | |
"Tucapel", | |
"Florida", | |
"Bulnes", | |
"Hualqui", | |
"Contulmo", | |
"Tomé", | |
"San Pedro de la Paz", | |
"Talcahuano", | |
"Tirúa", | |
"Negrete", | |
"Hualpén", | |
"San Fabián", | |
"Yungay", | |
"Quilaco", | |
"Portezuelo", | |
"Pinto", | |
"Antuco", | |
"Lebu", | |
"Pemuco", | |
"San Ignacio", | |
"Santa Juana", | |
"Santa Bárbara", | |
"Yumbel", | |
"San Nicolás", | |
"San Carlos", | |
"Lota", | |
"Treguaco", | |
"Cobquecura", | |
"El Carmen", | |
"Penco", | |
"Mulchén", | |
"Quirihue", | |
"Curanilahue" | |
], | |
"Región Metropolitana": [ | |
"Calera de Tango", | |
"El Monte", | |
"La Cisterna", | |
"Peñalolén", | |
"Tiltil", | |
"La Granja", | |
"Lo Espejo", | |
"Santiago", | |
"Renca", | |
"Vitacura", | |
"María Pinto", | |
"Paine", | |
"Conchalí", | |
"San Miguel", | |
"La Florida", | |
"Quilicura", | |
"Pedro Aguirre Cerda", | |
"Lampa", | |
"La Pintana", | |
"Isla de Maipo", | |
"Alhué", | |
"Providencia", | |
"Ñuñoa", | |
"El Bosque", | |
"Lo Prado", | |
"Independencia", | |
"Maipú", | |
"Recoleta", | |
"Macul", | |
"Cerro Navia", | |
"Lo Barnechea", | |
"Huechuraba", | |
"San Bernardo", | |
"San Joaquín", | |
"San José de Maipo", | |
"Buin", | |
"Estación Central", | |
"Quinta Normal", | |
"Curacaví", | |
"Talagante", | |
"Cerrillos", | |
"Peñaflor", | |
"Melipilla", | |
"San Pedro", | |
"Pudahuel", | |
"La Reina", | |
"San Ramón", | |
"Padre Hurtado", | |
"Pirque", | |
"Colina", | |
"Las Condes", | |
"Puente Alto" | |
], | |
"Región de Coquimbo": [ | |
"Salamanca", | |
"Río Hurtado", | |
"Canela", | |
"Vicuña", | |
"Andacollo", | |
"Combarbalá", | |
"Ovalle", | |
"Paiguano", | |
"La Serena", | |
"La Higuera", | |
"Monte Patria", | |
"Los Vilos", | |
"Coquimbo", | |
"Punitaqui", | |
"Illapel" | |
], | |
"Región de Aisén del General Carlos Ibañez del Campo": [ | |
"Cisnes", | |
"Aisén", | |
"Chile Chico", | |
"Río Ibáñez", | |
"Coihaique", | |
"Lago Verde", | |
"Cochrane", | |
"Guaitecas", | |
"O'Higgins", | |
"Tortel" | |
], | |
"Región de Tarapacá": [ | |
"Colchane", | |
"Iquique", | |
"Alto Hospicio", | |
"Camiña", | |
"Pozo Almonte", | |
"Huara", | |
"Pica" | |
], | |
"Región de los Lagos": [ | |
"Futaleufú", | |
"Puerto Octay", | |
"Puerto Varas", | |
"Calbuco", | |
"Hualaihué", | |
"Llanquihue", | |
"Dalcahue", | |
"Palena", | |
"Río Negro", | |
"Curaco de Vélez", | |
"Ancud", | |
"Castro", | |
"Puyehue", | |
"San Juan de la Costa", | |
"Quellón", | |
"Chonchi", | |
"Los Muermos", | |
"Queilén", | |
"Chaitén", | |
"Quemchi", | |
"Frutillar", | |
"Osorno", | |
"Fresia", | |
"Cochamó", | |
"Purranque", | |
"Puerto Montt", | |
"Quinchao", | |
"Maullín", | |
"Puqueldón", | |
"San Pablo" | |
] | |
} |
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
[ | |
"Arica", | |
"Camarones", | |
"Putre", | |
"General Lagos", | |
"Iquique", | |
"Alto Hospicio", | |
"Pozo Almonte", | |
"Camiña", | |
"Colchane", | |
"Huara", | |
"Pica", | |
"Antofagasta", | |
"Mejillones", | |
"Sierra Gorda", | |
"Taltal", | |
"Calama", | |
"Ollagüe", | |
"San Pedro de Atacama", | |
"Tocopilla", | |
"María Elena", | |
"Copiapó", | |
"Caldera", | |
"Tierra Amarilla", | |
"Chañaral", | |
"Diego de Almagro", | |
"Vallenar", | |
"Alto del Carmen", | |
"Freirina", | |
"Huasco", | |
"La Serena", | |
"Coquimbo", | |
"Andacollo", | |
"La Higuera", | |
"Paiguano", | |
"Vicuña", | |
"Illapel", | |
"Canela", | |
"Los Vilos", | |
"Salamanca", | |
"Ovalle", | |
"Combarbalá", | |
"Monte Patria", | |
"Punitaqui", | |
"Río Hurtado", | |
"Valparaíso", | |
"Casablanca", | |
"Concón", | |
"Juan Fernández", | |
"Puchuncaví", | |
"Quintero", | |
"Viña del Mar", | |
"Isla de Pascua", | |
"Los Andes", | |
"Calle Larga", | |
"Rinconada", | |
"San Esteban", | |
"La Ligua", | |
"Cabildo", | |
"Papudo", | |
"Petorca", | |
"Zapallar", | |
"Quillota", | |
"Calera", | |
"Hijuelas", | |
"La Cruz", | |
"Nogales", | |
"San Antonio", | |
"Algarrobo", | |
"Cartagena", | |
"El Quisco", | |
"El Tabo", | |
"Santo Domingo", | |
"San Felipe", | |
"Catemu", | |
"Llaillay", | |
"Panquehue", | |
"Putaendo", | |
"Santa María", | |
"Limache", | |
"Quilpué", | |
"Villa Alemana", | |
"Olmué", | |
"Rancagua", | |
"Codegua", | |
"Coinco", | |
"Coltauco", | |
"Doñihue", | |
"Graneros", | |
"Las Cabras", | |
"Machalí", | |
"Malloa", | |
"Mostazal", | |
"Olivar", | |
"Peumo", | |
"Pichidegua", | |
"Quinta de Tilcoco", | |
"Rengo", | |
"Requínoa", | |
"San Vicente", | |
"Pichilemu", | |
"La Estrella", | |
"Litueche", | |
"Marchihue", | |
"Navidad", | |
"Paredones", | |
"San Fernando", | |
"Chépica", | |
"Chimbarongo", | |
"Lolol", | |
"Nancagua", | |
"Palmilla", | |
"Peralillo", | |
"Placilla", | |
"Pumanque", | |
"Santa Cruz", | |
"Talca", | |
"Constitución", | |
"Curepto", | |
"Empedrado", | |
"Maule", | |
"Pelarco", | |
"Pencahue", | |
"Río Claro", | |
"San Clemente", | |
"San Rafael", | |
"Cauquenes", | |
"Chanco", | |
"Pelluhue", | |
"Curicó", | |
"Hualañé", | |
"Licantén", | |
"Molina", | |
"Rauco", | |
"Romeral", | |
"Sagrada Familia", | |
"Teno", | |
"Vichuquén", | |
"Linares", | |
"Colbún", | |
"Longaví", | |
"Parral", | |
"Retiro", | |
"San Javier", | |
"Villa Alegre", | |
"Yerbas Buenas", | |
"Concepción", | |
"Coronel", | |
"Chiguayante", | |
"Florida", | |
"Hualqui", | |
"Lota", | |
"Penco", | |
"San Pedro de la Paz", | |
"Santa Juana", | |
"Talcahuano", | |
"Tomé", | |
"Hualpén", | |
"Lebu", | |
"Arauco", | |
"Cañete", | |
"Contulmo", | |
"Curanilahue", | |
"Los Alamos", | |
"Tirúa", | |
"Los Angeles", | |
"Antuco", | |
"Cabrero", | |
"Laja", | |
"Mulchén", | |
"Nacimiento", | |
"Negrete", | |
"Quilaco", | |
"Quilleco", | |
"San Rosendo", | |
"Santa Bárbara", | |
"Tucapel", | |
"Yumbel", | |
"Alto Biobío", | |
"Chillán", | |
"Bulnes", | |
"Cobquecura", | |
"Coelemu", | |
"Coihueco", | |
"Chillán Viejo", | |
"El Carmen", | |
"Ninhue", | |
"Ñiquén", | |
"Pemuco", | |
"Pinto", | |
"Portezuelo", | |
"Quillón", | |
"Quirihue", | |
"Ránquil", | |
"San Carlos", | |
"San Fabián", | |
"San Ignacio", | |
"San Nicolás", | |
"Treguaco", | |
"Yungay", | |
"Temuco", | |
"Carahue", | |
"Cunco", | |
"Curarrehue", | |
"Freire", | |
"Galvarino", | |
"Gorbea", | |
"Lautaro", | |
"Loncoche", | |
"Melipeuco", | |
"Nueva Imperial", | |
"Padre Las Casas", | |
"Perquenco", | |
"Pitrufquén", | |
"Pucón", | |
"Saavedra", | |
"Teodoro Schmidt", | |
"Toltén", | |
"Vilcún", | |
"Villarrica", | |
"Cholchol", | |
"Angol", | |
"Collipulli", | |
"Curacautín", | |
"Ercilla", | |
"Lonquimay", | |
"Los Sauces", | |
"Lumaco", | |
"Purén", | |
"Renaico", | |
"Traiguén", | |
"Victoria", | |
"Valdivia", | |
"Corral", | |
"Lanco", | |
"Los Lagos", | |
"Máfil", | |
"Mariquina", | |
"Paillaco", | |
"Panguipulli", | |
"La Unión", | |
"Futrono", | |
"Lago Ranco", | |
"Río Bueno", | |
"Puerto Montt", | |
"Calbuco", | |
"Cochamó", | |
"Fresia", | |
"Frutillar", | |
"Los Muermos", | |
"Llanquihue", | |
"Maullín", | |
"Puerto Varas", | |
"Castro", | |
"Ancud", | |
"Chonchi", | |
"Curaco de Vélez", | |
"Dalcahue", | |
"Puqueldón", | |
"Queilén", | |
"Quellón", | |
"Quemchi", | |
"Quinchao", | |
"Osorno", | |
"Puerto Octay", | |
"Purranque", | |
"Puyehue", | |
"Río Negro", | |
"San Juan de la Costa", | |
"San Pablo", | |
"Chaitén", | |
"Futaleufú", | |
"Hualaihué", | |
"Palena", | |
"Coihaique", | |
"Lago Verde", | |
"Aisén", | |
"Cisnes", | |
"Guaitecas", | |
"Cochrane", | |
"O'Higgins", | |
"Tortel", | |
"Chile Chico", | |
"Río Ibáñez", | |
"Punta Arenas", | |
"Laguna Blanca", | |
"Río Verde", | |
"San Gregorio", | |
"Cabo de Hornos (Ex-Navarino)", | |
"Antártica", | |
"Porvenir", | |
"Primavera", | |
"Timaukel", | |
"Natales", | |
"Torres del Paine", | |
"Santiago", | |
"Cerrillos", | |
"Cerro Navia", | |
"Conchalí", | |
"El Bosque", | |
"Estación Central", | |
"Huechuraba", | |
"Independencia", | |
"La Cisterna", | |
"La Florida", | |
"La Granja", | |
"La Pintana", | |
"La Reina", | |
"Las Condes", | |
"Lo Barnechea", | |
"Lo Espejo", | |
"Lo Prado", | |
"Macul", | |
"Maipú", | |
"Ñuñoa", | |
"Pedro Aguirre Cerda", | |
"Peñalolén", | |
"Providencia", | |
"Pudahuel", | |
"Quilicura", | |
"Quinta Normal", | |
"Recoleta", | |
"Renca", | |
"San Joaquín", | |
"San Miguel", | |
"San Ramón", | |
"Vitacura", | |
"Puente Alto", | |
"Pirque", | |
"San José de Maipo", | |
"Colina", | |
"Lampa", | |
"Tiltil", | |
"San Bernardo", | |
"Buin", | |
"Calera de Tango", | |
"Paine", | |
"Melipilla", | |
"Alhué", | |
"Curacaví", | |
"María Pinto", | |
"San Pedro", | |
"Talagante", | |
"El Monte", | |
"Isla de Maipo", | |
"Padre Hurtado", | |
"Peñaflor" | |
] |
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
<!-- http://www.subdere.gov.cl/documentacion/regiones-provincias-y-comunas-de-chile | |
TOTAL REGIONES : 15 | |
TOTAL PROVINCIAS : 54 | |
TOTAL COMUNAS : 346 | |
--> | |
<html> | |
<body> | |
<p><strong><font size="3">1. REGIÓN: ARICA Y PARINACOTA (2 provincias - 4 comunas)</font></strong></p> | |
<p><strong>1. PROVINCIA : Arica</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Arica</li> | |
<li> | |
Camarones</li> | |
</ul> | |
<p><strong>2. PROVINCIA : Parinacota</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Putre</li> | |
<li> | |
General Lagos</li> | |
</ul> | |
<p><strong><font size="3">2. REGIÓN: TARAPACÁ (2 provincias - 7 comunas)</font></strong></p> | |
<p><strong>3. PROVINCIA : Iquique</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Iquique</li> | |
<li> | |
Alto Hospicio</li> | |
</ul> | |
<p><strong>4. PROVINCIA : Tamarugal</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
Pozo Almonte</li> | |
<li> | |
Camiña</li> | |
<li> | |
Colchane</li> | |
<li> | |
Huara</li> | |
<li> | |
Pica</li> | |
</ul> | |
<p><strong><font size="3">3. REGION: ANTOFAGASTA (3 PROVINCIAS - 9 COMUNAS)</font></strong></p> | |
<p><strong>5. PROVINCIA : Antofagasta</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Antofagasta</li> | |
<li> | |
Mejillones</li> | |
<li> | |
Sierra Gorda</li> | |
<li> | |
Taltal</li> | |
</ul> | |
<p><strong>6. PROVINCIA : El Loa</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Calama</li> | |
<li> | |
Ollagüe</li> | |
<li> | |
San Pedro de Atacama</li> | |
</ul> | |
<p><strong>7. PROVINCIA : Tocopilla</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Tocopilla</li> | |
<li> | |
María Elena</li> | |
</ul> | |
<p><strong><font size="3">4. REGIÓN: ATACAMA (3 PROVINCIAS - 9 COMUNAS)</font></strong></p> | |
<p><strong>8. PROVINCIA : Copiapó</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Copiapó</li> | |
<li> | |
Caldera</li> | |
<li> | |
Tierra Amarilla</li> | |
</ul> | |
<p><strong>9. PROVINCIA : Chañaral</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Chañaral</li> | |
<li> | |
Diego de Almagro</li> | |
</ul> | |
<p><strong>10. PROVINCIA : Huasco</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Vallenar</li> | |
<li> | |
Alto del Carmen</li> | |
<li> | |
Freirina</li> | |
<li> | |
Huasco</li> | |
</ul> | |
<p><strong><font size="3">5. REGIÓN: COQUIMBO (3 PROVINCIAS - 15 COMUNAS)</font></strong></p> | |
<p><strong>11. PROVINCIA : Elqui</strong></p> | |
<p>COMUNAS : 6</p> | |
<ul> | |
<li> | |
La Serena</li> | |
<li> | |
Coquimbo</li> | |
<li> | |
Andacollo</li> | |
<li> | |
La Higuera</li> | |
<li> | |
Paiguano</li> | |
<li> | |
Vicuña</li> | |
</ul> | |
<p><strong>12. PROVINCIA : Choapa</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Illapel</li> | |
<li> | |
Canela</li> | |
<li> | |
Los Vilos</li> | |
<li> | |
Salamanca</li> | |
</ul> | |
<p><strong>13. PROVINCIA : Limarí</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
Ovalle</li> | |
<li> | |
Combarbalá</li> | |
<li> | |
Monte Patria</li> | |
<li> | |
Punitaqui</li> | |
<li> | |
Río Hurtado</li> | |
</ul> | |
<p><strong><font size="3">6. REGION: VALPARAÍSO (8 PROVINCIAS - 38 COMUNAS)</font></strong></p> | |
<p><strong>14. PROVINCIA : Valparaíso</strong></p> | |
<p>COMUNAS : 7</p> | |
<ul> | |
<li> | |
Valparaíso</li> | |
<li> | |
Casablanca</li> | |
<li> | |
Concón</li> | |
<li> | |
Juan Fernández</li> | |
<li> | |
Puchuncaví</li> | |
<li> | |
Quintero</li> | |
<li> | |
Viña del Mar</li> | |
</ul> | |
<p><strong>15. PROVINCIA : Isla de Pascua</strong></p> | |
<p>COMUNA : 1</p> | |
<ul> | |
<li> | |
Isla de Pascua</li> | |
</ul> | |
<p><strong>16. PROVINCIA : Los Andes</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Los Andes</li> | |
<li> | |
Calle Larga</li> | |
<li> | |
Rinconada</li> | |
<li> | |
San Esteban</li> | |
</ul> | |
<p><strong>17. PROVINCIA : Petorca</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
La Ligua</li> | |
<li> | |
Cabildo</li> | |
<li> | |
Papudo</li> | |
<li> | |
Petorca</li> | |
<li> | |
Zapallar</li> | |
</ul> | |
<p><strong>18. PROVINCIA : Quillota</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
Quillota</li> | |
<li> | |
Calera</li> | |
<li> | |
Hijuelas</li> | |
<li> | |
La Cruz</li> | |
<li> | |
Nogales</li> | |
</ul> | |
<p><strong>19. PROVINCIA : San Antonio</strong></p> | |
<p>COMUNAS : 6</p> | |
<ul> | |
<li> | |
San Antonio</li> | |
<li> | |
Algarrobo</li> | |
<li> | |
Cartagena</li> | |
<li> | |
El Quisco</li> | |
<li> | |
El Tabo</li> | |
<li> | |
Santo Domingo</li> | |
</ul> | |
<p><strong>20. PROVINCIA : San Felipe de Aconcagua</strong></p> | |
<p>COMUNAS : 6</p> | |
<ul> | |
<li> | |
San Felipe</li> | |
<li> | |
Catemu</li> | |
<li> | |
Llaillay</li> | |
<li> | |
Panquehue</li> | |
<li> | |
Putaendo</li> | |
<li> | |
Santa María</li> | |
</ul> | |
<p><strong>21. PROVINCIA : Marga Marga</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Limache</li> | |
<li> | |
Quilpué</li> | |
<li> | |
Villa Alemana</li> | |
<li> | |
Olmué</li> | |
</ul> | |
<p><strong><font size="3">7. REGION: DEL LIBERTADOR GRAL. BERNARDO O'HIGGINS (3 PROVINCIAS - 33 COMUNAS)</font></strong></p> | |
<p><strong>22. PROVINCIA : Cachapoal</strong></p> | |
<p>COMUNAS : 17</p> | |
<ul> | |
<li> | |
Rancagua</li> | |
<li> | |
Codegua</li> | |
<li> | |
Coinco</li> | |
<li> | |
Coltauco</li> | |
<li> | |
Doñihue</li> | |
<li> | |
Graneros</li> | |
<li> | |
Las Cabras</li> | |
<li> | |
Machalí</li> | |
<li> | |
Malloa</li> | |
<li> | |
Mostazal</li> | |
<li> | |
Olivar</li> | |
<li> | |
Peumo</li> | |
<li> | |
Pichidegua</li> | |
<li> | |
Quinta de Tilcoco</li> | |
<li> | |
Rengo</li> | |
<li> | |
Requínoa</li> | |
<li> | |
San Vicente</li> | |
</ul> | |
<p><strong>23. PROVINCIA : Cardenal Caro</strong></p> | |
<p>COMUNAS : 6</p> | |
<ul> | |
<li> | |
Pichilemu</li> | |
<li> | |
La Estrella</li> | |
<li> | |
Litueche</li> | |
<li> | |
Marchihue</li> | |
<li> | |
Navidad</li> | |
<li> | |
Paredones</li> | |
</ul> | |
<p><strong>24. PROVINCIA : Colchagua</strong></p> | |
<p>COMUNAS : 10</p> | |
<ul> | |
<li> | |
San Fernando</li> | |
<li> | |
Chépica</li> | |
<li> | |
Chimbarongo</li> | |
<li> | |
Lolol</li> | |
<li> | |
Nancagua</li> | |
<li> | |
Palmilla</li> | |
<li> | |
Peralillo</li> | |
<li> | |
Placilla</li> | |
<li> | |
Pumanque</li> | |
<li> | |
Santa Cruz</li> | |
</ul> | |
<p><strong><font size="3">8. REGIÓN: DEL MAULE (4 PROVINCIAS - 30 COMUNAS)</font></strong></p> | |
<p><strong>25. PROVINCIA : Talca</strong></p> | |
<p>COMUNAS : 10</p> | |
<ul> | |
<li> | |
Talca</li> | |
<li> | |
Constitución</li> | |
<li> | |
Curepto</li> | |
<li> | |
Empedrado</li> | |
<li> | |
Maule</li> | |
<li> | |
Pelarco</li> | |
<li> | |
Pencahue</li> | |
<li> | |
Río Claro</li> | |
<li> | |
San Clemente</li> | |
<li> | |
San Rafael</li> | |
</ul> | |
<p><strong>26. PROVINCIA : Cauquenes</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Cauquenes</li> | |
<li> | |
Chanco</li> | |
<li> | |
Pelluhue</li> | |
</ul> | |
<p><strong>27. PROVINCIA : Curicó</strong></p> | |
<p>COMUNAS : 9</p> | |
<ul> | |
<li> | |
Curicó</li> | |
<li> | |
Hualañé</li> | |
<li> | |
Licantén</li> | |
<li> | |
Molina</li> | |
<li> | |
Rauco</li> | |
<li> | |
Romeral</li> | |
<li> | |
Sagrada Familia</li> | |
<li> | |
Teno</li> | |
<li> | |
Vichuquén</li> | |
</ul> | |
<p><strong>28. PROVINCIA : Linares</strong></p> | |
<p>COMUNAS : 8</p> | |
<ul> | |
<li> | |
Linares</li> | |
<li> | |
Colbún</li> | |
<li> | |
Longaví</li> | |
<li> | |
Parral</li> | |
<li> | |
Retiro</li> | |
<li> | |
San Javier</li> | |
<li> | |
Villa Alegre</li> | |
<li> | |
Yerbas Buenas</li> | |
</ul> | |
<p><strong><font size="3">9. REGIÓN: DEL BIOBÍO (4 PROVINCIAS - 54 COMUNAS)</font></strong></p> | |
<p><strong>29. PROVINCIA : Concepción</strong></p> | |
<p>COMUNAS : 12</p> | |
<ul> | |
<li> | |
Concepción</li> | |
<li> | |
Coronel</li> | |
<li> | |
Chiguayante</li> | |
<li> | |
Florida</li> | |
<li> | |
Hualqui</li> | |
<li> | |
Lota</li> | |
<li> | |
Penco</li> | |
<li> | |
San Pedro de la Paz</li> | |
<li> | |
Santa Juana</li> | |
<li> | |
Talcahuano</li> | |
<li> | |
Tomé</li> | |
<li> | |
Hualpén</li> | |
</ul> | |
<p><strong>30. PROVINCIA : Arauco</strong></p> | |
<p>COMUNAS : 7</p> | |
<ul> | |
<li> | |
Lebu</li> | |
<li> | |
Arauco</li> | |
<li> | |
Cañete</li> | |
<li> | |
Contulmo</li> | |
<li> | |
Curanilahue</li> | |
<li> | |
Los Alamos</li> | |
<li> | |
Tirúa</li> | |
</ul> | |
<p><strong>31. PROVINCIA : Biobío</strong></p> | |
<p>COMUNAS : 14</p> | |
<ul> | |
<li> | |
Los Angeles</li> | |
<li> | |
Antuco</li> | |
<li> | |
Cabrero</li> | |
<li> | |
Laja</li> | |
<li> | |
Mulchén</li> | |
<li> | |
Nacimiento</li> | |
<li> | |
Negrete</li> | |
<li> | |
Quilaco</li> | |
<li> | |
Quilleco</li> | |
<li> | |
San Rosendo</li> | |
<li> | |
Santa Bárbara</li> | |
<li> | |
Tucapel</li> | |
<li> | |
Yumbel</li> | |
<li> | |
Alto Biobío</li> | |
</ul> | |
<p><strong>32. PROVINCIA : Ñuble</strong></p> | |
<p>COMUNAS : 21</p> | |
<ul> | |
<li> | |
Chillán</li> | |
<li> | |
Bulnes</li> | |
<li> | |
Cobquecura</li> | |
<li> | |
Coelemu</li> | |
<li> | |
Coihueco</li> | |
<li> | |
Chillán Viejo</li> | |
<li> | |
El Carmen</li> | |
<li> | |
Ninhue</li> | |
<li> | |
Ñiquén</li> | |
<li> | |
Pemuco</li> | |
<li> | |
Pinto</li> | |
<li> | |
Portezuelo</li> | |
<li> | |
Quillón</li> | |
<li> | |
Quirihue</li> | |
<li> | |
Ránquil</li> | |
<li> | |
San Carlos</li> | |
<li> | |
San Fabián</li> | |
<li> | |
San Ignacio</li> | |
<li> | |
San Nicolás</li> | |
<li> | |
Treguaco</li> | |
<li> | |
Yungay</li> | |
</ul> | |
<p><strong><font size="3">10. REGIÓN: DE LA ARAUCANÍA (2 PROVINCIAS - 32 COMUNAS)</font></strong></p> | |
<p><strong>33. PROVINCIA : Cautín</strong></p> | |
<p>COMUNAS : 21</p> | |
<ul> | |
<li> | |
Temuco</li> | |
<li> | |
Carahue</li> | |
<li> | |
Cunco</li> | |
<li> | |
Curarrehue</li> | |
<li> | |
Freire</li> | |
<li> | |
Galvarino</li> | |
<li> | |
Gorbea</li> | |
<li> | |
Lautaro</li> | |
<li> | |
Loncoche</li> | |
<li> | |
Melipeuco</li> | |
<li> | |
Nueva Imperial</li> | |
<li> | |
Padre Las Casas</li> | |
<li> | |
Perquenco</li> | |
<li> | |
Pitrufquén</li> | |
<li> | |
Pucón</li> | |
<li> | |
Saavedra</li> | |
<li> | |
Teodoro Schmidt</li> | |
<li> | |
Toltén</li> | |
<li> | |
Vilcún</li> | |
<li> | |
Villarrica</li> | |
<li> | |
Cholchol</li> | |
</ul> | |
<p><strong>34. PROVINCIA : Malleco</strong></p> | |
<p>COMUNAS : 11</p> | |
<ul> | |
<li> | |
Angol</li> | |
<li> | |
Collipulli</li> | |
<li> | |
Curacautín</li> | |
<li> | |
Ercilla</li> | |
<li> | |
Lonquimay</li> | |
<li> | |
Los Sauces</li> | |
<li> | |
Lumaco</li> | |
<li> | |
Purén</li> | |
<li> | |
Renaico</li> | |
<li> | |
Traiguén</li> | |
<li> | |
Victoria</li> | |
</ul> | |
<p><strong><font size="3">11. REGIÓN: DE LOS RÍOS (2 PROVINCIAS - 12 COMUNAS)</font></strong></p> | |
<p><strong>35. PROVINCIA : Valdivia</strong></p> | |
<p>COMUNAS : 8</p> | |
<ul> | |
<li> | |
Valdivia</li> | |
<li> | |
Corral</li> | |
<li> | |
Lanco</li> | |
<li> | |
Los Lagos</li> | |
<li> | |
Máfil</li> | |
<li> | |
Mariquina</li> | |
<li> | |
Paillaco</li> | |
<li> | |
Panguipulli</li> | |
</ul> | |
<p><strong>36. PROVINCIA : Ranco</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
La Unión</li> | |
<li> | |
Futrono</li> | |
<li> | |
Lago Ranco</li> | |
<li> | |
Río Bueno</li> | |
</ul> | |
<p><strong><font size="3">12. REGIÓN: DE LOS LAGOS (4 PROVINCIAS - 30 COMUNAS)</font></strong></p> | |
<p><strong>37. PROVINCIA : Llanquihue</strong></p> | |
<p>COMUNAS : 9</p> | |
<ul> | |
<li> | |
Puerto Montt</li> | |
<li> | |
Calbuco</li> | |
<li> | |
Cochamó</li> | |
<li> | |
Fresia</li> | |
<li> | |
Frutillar</li> | |
<li> | |
Los Muermos</li> | |
<li> | |
Llanquihue</li> | |
<li> | |
Maullín</li> | |
<li> | |
Puerto Varas</li> | |
</ul> | |
<p><strong>38. PROVINCIA : Chiloé</strong></p> | |
<p>COMUNAS : 10</p> | |
<ul> | |
<li> | |
Castro</li> | |
<li> | |
Ancud</li> | |
<li> | |
Chonchi</li> | |
<li> | |
Curaco de Vélez</li> | |
<li> | |
Dalcahue</li> | |
<li> | |
Puqueldón</li> | |
<li> | |
Queilén</li> | |
<li> | |
Quellón</li> | |
<li> | |
Quemchi</li> | |
<li> | |
Quinchao</li> | |
</ul> | |
<p><strong>39. PROVINCIA : Osorno</strong></p> | |
<p>COMUNAS : 7</p> | |
<ul> | |
<li> | |
Osorno</li> | |
<li> | |
Puerto Octay</li> | |
<li> | |
Purranque</li> | |
<li> | |
Puyehue</li> | |
<li> | |
Río Negro</li> | |
<li> | |
San Juan de la Costa</li> | |
<li> | |
San Pablo</li> | |
</ul> | |
<p><strong>40. PROVINCIA : Palena</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Chaitén</li> | |
<li> | |
Futaleufú</li> | |
<li> | |
Hualaihué</li> | |
<li> | |
Palena</li> | |
</ul> | |
<p><strong><font size="3">13. REGIÓN: AISÉN DEL GRAL. CARLOS IBAÑEZ DEL CAMPO (4 PROVINCIAS - 10 COMUNAS)</font></strong></p> | |
<p><strong>41. PROVINCIA : Coihaique</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Coihaique</li> | |
<li> | |
Lago Verde</li> | |
</ul> | |
<p><strong>42. PROVINCIA : Aisén</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Aisén</li> | |
<li> | |
Cisnes</li> | |
<li> | |
Guaitecas</li> | |
</ul> | |
<p><strong>43. PROVINCIA : Capitán Prat</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Cochrane</li> | |
<li> | |
O'Higgins</li> | |
<li> | |
Tortel</li> | |
</ul> | |
<p><strong>44. PROVINCIA : General Carrera</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Chile Chico</li> | |
<li> | |
Río Ibáñez</li> | |
</ul> | |
<p><strong><font size="3">14. REGIÓN: MAGALLANES Y DE LA ANTÁRTICA CHILENA (4 PROVINCIAS - 11 COMUNAS)</font></strong></p> | |
<p><strong>45. PROVINCIA : Magallanes</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
Punta Arenas</li> | |
<li> | |
Laguna Blanca</li> | |
<li> | |
Río Verde</li> | |
<li> | |
San Gregorio</li> | |
</ul> | |
<p><strong>46. PROVINCIA : Antártica Chilena</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Cabo de Hornos (Ex-Navarino)</li> | |
<li> | |
Antártica</li> | |
</ul> | |
<p><strong>47. PROVINCIA : Tierra del Fuego</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Porvenir</li> | |
<li> | |
Primavera</li> | |
<li> | |
Timaukel</li> | |
</ul> | |
<p><strong>48. PROVINCIA : Ultima Esperanza</strong></p> | |
<p>COMUNAS : 2</p> | |
<ul> | |
<li> | |
Natales</li> | |
<li> | |
Torres del Paine</li> | |
</ul> | |
<p><strong><font size="3">15. REGIÓN METROPOLITANA DE SANTIAGO (6 PROVINCIAS - 52 COMUNAS)</font></strong></p> | |
<p><strong>49. PROVINCIA : Santiago</strong></p> | |
<p>COMUNAS : 32</p> | |
<ul> | |
<li> | |
Santiago</li> | |
<li> | |
Cerrillos</li> | |
<li> | |
Cerro Navia</li> | |
<li> | |
Conchalí</li> | |
<li> | |
El Bosque</li> | |
<li> | |
Estación Central</li> | |
<li> | |
Huechuraba</li> | |
<li> | |
Independencia</li> | |
<li> | |
La Cisterna</li> | |
<li> | |
La Florida</li> | |
<li> | |
La Granja</li> | |
<li> | |
La Pintana</li> | |
<li> | |
La Reina</li> | |
<li> | |
Las Condes</li> | |
<li> | |
Lo Barnechea</li> | |
<li> | |
Lo Espejo</li> | |
<li> | |
Lo Prado</li> | |
<li> | |
Macul</li> | |
<li> | |
Maipú</li> | |
<li> | |
Ñuñoa</li> | |
<li> | |
Pedro Aguirre Cerda</li> | |
<li> | |
Peñalolén</li> | |
<li> | |
Providencia</li> | |
<li> | |
Pudahuel</li> | |
<li> | |
Quilicura</li> | |
<li> | |
Quinta Normal</li> | |
<li> | |
Recoleta</li> | |
<li> | |
Renca</li> | |
<li> | |
San Joaquín</li> | |
<li> | |
San Miguel</li> | |
<li> | |
San Ramón</li> | |
<li> | |
Vitacura</li> | |
</ul> | |
<p><strong>50. PROVINCIA : CORDILLERA</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Puente Alto</li> | |
<li> | |
Pirque</li> | |
<li> | |
San José de Maipo</li> | |
</ul> | |
<p><strong>51. PROVINCIA : Chacabuco</strong></p> | |
<p>COMUNAS : 3</p> | |
<ul> | |
<li> | |
Colina</li> | |
<li> | |
Lampa</li> | |
<li> | |
Tiltil</li> | |
</ul> | |
<p><strong>52. PROVINCIA : Maipo</strong></p> | |
<p>COMUNAS : 4</p> | |
<ul> | |
<li> | |
San Bernardo</li> | |
<li> | |
Buin</li> | |
<li> | |
Calera de Tango</li> | |
<li> | |
Paine</li> | |
</ul> | |
<p><strong>53. PROVINCIA : Melipilla</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
Melipilla</li> | |
<li> | |
Alhué</li> | |
<li> | |
Curacaví</li> | |
<li> | |
María Pinto</li> | |
<li> | |
San Pedro</li> | |
</ul> | |
<p><strong>54. PROVINCIA : Talagante</strong></p> | |
<p>COMUNAS : 5</p> | |
<ul> | |
<li> | |
Talagante</li> | |
<li> | |
El Monte</li> | |
<li> | |
Isla de Maipo</li> | |
<li> | |
Padre Hurtado</li> | |
<li> | |
Peñaflor</li> | |
</ul> | |
</body> | |
</html> |
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
# coding: utf-8 | |
u"""Organización territorial de Chile a Noviembre de 2012. | |
"Base de datos incluye regiones, provincias y comunas y archivo con Códigos | |
Únicos Territoriales modificados por Decreto Exento Nº 817, del Ministerio del | |
Interior, publicado en el Diario Oficial del 26 de Marzo de 2010. Al crearse la | |
provincia de Marga Marga se asignó código a la nueva provincia y se modificó el | |
de sus comunas constitutivas." | |
REGIONES: 15 | |
PROVINCIAS: 54 | |
COMUNAS: 346 | |
Fuentes: | |
* Gist | Chile: Regiones, Provincias, Comunas | |
https://gist.github.com/4090294 | |
* Subdere | Documentación | Regiones, Provincias y Comunas de Chile | |
http://www.subdere.gov.cl/documentacion/regiones-provincias-y-comunas-de-chile | |
* DIVISIÓN POLÍTICO ADMINISTRATIVA DE CHILE: REGIONES – PROVINCIAS – COMUNAS | |
http://www.subdere.gov.cl/sites/default/files/documentos/articles-73111_recurso_1.pdf | |
""" | |
from django.db import models as mo | |
class UnidadTerritorial(mo.Model): | |
u"""Abstracción de los conceptos de Región, Provincia y Comuna.""" | |
class Meta: | |
abstract = True | |
codigo = mo.CharField('código', max_length=5) | |
nombre_corto = mo.CharField(max_length=50, | |
help_text="Gral. Bernardo O'Higgins") | |
nombre_largo = mo.CharField(max_length=100, blank=True, | |
help_text="Región del Libertador General Bernardo O'Higgins") | |
def __unicode__(self): | |
return self.nombre_corto | |
class Region(UnidadTerritorial): | |
class Meta: | |
verbose_name = u'región' | |
verbose_name_plural = u'regiones' | |
class Provincia(UnidadTerritorial): | |
region = mo.ForeignKey(Region, verbose_name='región') | |
class Comuna(UnidadTerritorial): | |
provincia = mo.ForeignKey(Provincia) |
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 json | |
from x.models import Region, Provincia, Comuna | |
provincias = json.load(file('provincias.json')) | |
for prov in provincias: | |
reg = provincias[prov] | |
obj, created = Region.objects.get_or_create(nombre_corto=reg) | |
Provincia.objects.create(nombre_corto=prov, region=obj) | |
comunas = json.load(file('comunas.json')) | |
for com in comunas: | |
prov = comunas[com] | |
obj, created = Provincia.objects.get_or_create(nombre_corto=prov) | |
Comuna.objects.create(nombre_corto=com, provincia=obj) | |
Region.objects.count() # 15 | |
Provincia.objects.count() # 54 | |
Comuna.objects.count() # 346 | |
Provincia.objects.filter(region__nombre_corto__icontains=u"BERNARDO") | |
# [<Provincia: 23. PROVINCIA : Cardenal Caro>, <Provincia: 22. PROVINCIA : Cachapoal>, <Provincia: 24. PROVINCIA : Colchagua>] | |
Comuna.objects.filter(provincia__region__nombre_corto__icontains=u"BERNARDO") | |
# [<Comuna: Litueche>, <Comuna: Pichilemu>, <Comuna: La Estrella>, <Comuna: Marchihue>, <Comuna: Paredones>, <Comuna: Navidad>, <Comuna: Peumo>, <Comuna: Machalí>, <Comuna: Graneros>, <Comuna: Codegua>, <Comuna: Quinta de Tilcoco>, <Comuna: Olivar>, <Comuna: Coltauco>, <Comuna: Coinco>, <Comuna: Pichidegua>, <Comuna: Rancagua>, <Comuna: Malloa>, <Comuna: Las Cabras>, <Comuna: San Vicente>, <Comuna: Rengo>, '...(remaining elements truncated)...'] |
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 json | |
from bs4 import BeautifulSoup | |
soup = BeautifulSoup(open('datos.html'), 'html.parser') | |
uls = soup.findAll('ul') | |
provincias = {} | |
comunas = {} | |
for provincia_ul in uls: | |
provincia_tag = provincia_ul.previous_sibling.previous_sibling.previous_sibling.previous_sibling | |
provincia_str = str(provincia_tag.strong.string) | |
try: | |
region_str = str(provincia_tag.previous_sibling.previous_sibling.strong.font.string) | |
provincias[provincia_str] = region_str | |
except AttributeError: | |
pre_provincia_tag = provincia_tag.previous_sibling.previous_sibling.previous_sibling.previous_sibling.previous_sibling.previous_sibling | |
pre_provincia_str = str(pre_provincia_tag.strong.string) | |
provincias[provincia_str] = provincias[pre_provincia_str] | |
for c in provincia_ul.stripped_strings: | |
comunas[c] = provincia_str | |
with open('comunas.json', 'w') as f: | |
json.dump(comunas, f, indent=2) | |
with open('provincias.json', 'w') as f: | |
json.dump(provincias, f, indent=2) |
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
#!/usr/bin/env python3 | |
import json | |
from bs4 import BeautifulSoup | |
def scrape_comunas(html_filename): | |
comunas_list = [] | |
soup = BeautifulSoup(open(html_filename), 'html.parser') | |
uls = soup.findAll('ul') | |
for ul in uls: | |
comunas_list.extend(list(ul.stripped_strings)) | |
return comunas_list | |
def write_comunas(json_filename): | |
with open(json_filename, 'w') as f: | |
# print as utf-8 i.e. don't escape non-ASCII chars such as 'ñ' | |
json.dump(comunas, f, ensure_ascii=False, indent=2) | |
if __name__ == '__main__': | |
comunas = scrape_comunas('datos.html') | |
write_comunas('comunas.json') | |
print("processed and saved %s 'comunas'" % len(comunas)) |
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
#!/usr/bin/env python3 | |
"""Extract from a HTML file a map of "comunas" per "región" (Chile). | |
Sadly, names of "regiones" have to be edited by hand. | |
Input: 'datos.html' | |
Output: 'region_comunas_map.json' | |
""" | |
import json | |
from bs4 import BeautifulSoup | |
def scrape_html_file(filename): | |
provincias = {} | |
comunas = {} | |
soup = BeautifulSoup(open(filename), 'html.parser') | |
uls = soup.findAll('ul') | |
for provincia_ul in uls: | |
provincia_tag = (provincia_ul.previous_sibling | |
.previous_sibling | |
.previous_sibling | |
.previous_sibling) | |
provincia_str = str(provincia_tag.strong.string) | |
try: | |
region_str = str(provincia_tag.previous_sibling | |
.previous_sibling | |
.strong | |
.font | |
.string) | |
except AttributeError: | |
pre_provincia_tag = (provincia_tag.previous_sibling | |
.previous_sibling | |
.previous_sibling | |
.previous_sibling | |
.previous_sibling | |
.previous_sibling) | |
pre_provincia_str = str(pre_provincia_tag.strong.string) | |
region_str = provincias[pre_provincia_str] | |
for c in provincia_ul.stripped_strings: | |
comunas[c] = provincia_str | |
provincias[provincia_str] = region_str | |
return provincias, comunas | |
def get_region_comunas_map(provincias, comunas): | |
regiones_set = set(provincias.values()) | |
region_comunas_map = {key: [] for key in regiones_set} | |
for comuna in comunas: | |
provincia = comunas[comuna] | |
region = provincias[provincia] | |
region_comunas_map[region].append(comuna) | |
return region_comunas_map | |
def main(html_filename, json_filename): | |
provincias, comunas = scrape_html_file(html_filename) | |
region_comunas_map = get_region_comunas_map(provincias, comunas) | |
with open(json_filename, 'w') as f: | |
# print as utf-8 i.e. don't escape non-ASCII chars such as 'ñ' | |
json.dump(region_comunas_map, f, ensure_ascii=False, indent=2) | |
if __name__ == '__main__': | |
main('datos.html', 'region_comunas_map.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment