Last active
August 19, 2017 18:12
-
-
Save sergiolucero/7770c40915537ccab5dbe6653f4772f9 to your computer and use it in GitHub Desktop.
How to pull population from wikipedia pages
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 wikipedia | |
CITIES=['Paris','Barcelona','Tokyo', 'New York City','Amsterdam','Copenhaguen','San Francisco'] | |
AMBIGUOUS_CITIES = ['Santiago'] # need to dig deeper, 'population' is not contained in the summary | |
for city in CITIES: | |
citywiki = wikipedia.page(city) | |
cwsum = citywiki.summary | |
poploc = cwsum.index('population') # first and only? | |
print(city, cwsum[poploc:poploc+30]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment