Created
January 5, 2020 12:01
-
-
Save Irio/b31a0be9ca7e1391118628d3dde3c975 to your computer and use it in GitHub Desktop.
Brazilian municipalities and their Wikipedia links
This file contains hidden or 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
| // Run with: | |
| // $ go get github.com/MontFerret/ferret | |
| // $ ferret municipalities.fql > municipalities.json | |
| LET baseURL = "https://pt.wikipedia.org" | |
| LET startURL = CONCAT(baseURL, "/wiki/Lista_de_munic%C3%ADpios_do_Brasil_por_popula%C3%A7%C3%A3o") | |
| LET municipalitySelector = ".wikitable tbody tr:not(:nth-child(1))" | |
| LET doc = DOCUMENT(startURL) | |
| FOR row in ELEMENTS(doc, municipalitySelector) | |
| LET ibgeID = TRIM(ELEMENT(row, "td:nth-child(2)").innerText) | |
| LET name = TRIM(ELEMENT(row, "td:nth-child(3)").innerText) | |
| LET federativeUnit = TRIM(ELEMENT(row, "td:nth-child(4)").innerText) | |
| LET population = TO_INT(TRIM(ELEMENT(row, "td:nth-child(5)").innerText)) | |
| LET municipalityURL = CONCAT(baseURL, ELEMENT(row, "td:nth-child(3) a").attributes.href) | |
| LET doc = DOCUMENT(municipalityURL) | |
| LET URLs = ( | |
| FOR URL IN ELEMENTS(doc, ".infobox_v2 tr:last-child td .external") | |
| RETURN URL.attributes.href | |
| ) | |
| RETURN { | |
| ibge_id: ibgeID, | |
| name, | |
| federative_unit: federativeUnit, | |
| urls: URLs, | |
| wikipedia_url: municipalityURL, | |
| population | |
| } |
This file has been truncated, but you can view the full file.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment