Created
September 5, 2016 09:47
-
-
Save zverok/e6dd3e43e2deb0b2f434ded9ac320d72 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
require 'infoboxer' | |
page = Infoboxer.wikipedia.get('List of urban areas by population') | |
res = page | |
.sections(/Urban areas/).tables.first | |
.rows[1..-1].map { |r| | |
{ | |
city: r.cells[2].to_s, | |
country: r.cells.templates.first.name, # What you see as Japan on page, in page code looks like {{JPN}} | |
population: r.cells[4].to_s | |
} | |
} | |
p res.first(3) | |
# => [{:city=>"Tokyo–Yokohama (Keihin)", :country=>"JPN", :population=>"37,750,000"}, {:city=>"Jakarta (Jabodetabek)", :country=>"IDN", :population=>"30,091,131"}, {:city=>"Delhi (NCR)", :country=>"IND", :population=>"24,998,000"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment