Skip to content

Instantly share code, notes, and snippets.

@zverok
Created September 5, 2016 09:47
Show Gist options
  • Save zverok/e6dd3e43e2deb0b2f434ded9ac320d72 to your computer and use it in GitHub Desktop.
Save zverok/e6dd3e43e2deb0b2f434ded9ac320d72 to your computer and use it in GitHub Desktop.
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