Skip to content

Instantly share code, notes, and snippets.

@fellix
Forked from manfe/script.rb
Created October 23, 2012 16:51
Show Gist options
  • Save fellix/3940036 to your computer and use it in GitHub Desktop.
Save fellix/3940036 to your computer and use it in GitHub Desktop.
Recuperando Cidades de Estados Brasileiros
require 'nokogiri'
require 'htmlentities'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.ibge.gov.br/cidadesat/includes/ac.inc'))
doc = doc.xpath('//p')
doc.each do |c|
@variables = c.text
end
estado = @variables.match(/uf=(.*?);/)[1]
municipios = @variables.match(/mundata=(.*?);/)[1]
municipios = eval(municipios)
result = { estado.to_sym => municipios }
p result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment