Skip to content

Instantly share code, notes, and snippets.

@antoniocuga
Created February 16, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniocuga/7822715e07364d9580c7 to your computer and use it in GitHub Desktop.
Save antoniocuga/7822715e07364d9580c7 to your computer and use it in GitHub Desktop.
Extract all politicians groups
require 'nokogiri'
require 'open-uri'
require 'csv'
//Save the content into CSV
CSV.open("partidos.csv", "w") do |csv|
csv << ['ruc','partido']
// 1 to 5, differents types of politicians groups
for i in 1...5
//ONPE URL
url = 'http://www.web.onpe.gob.pe/aportes-cargar-partidos-ajax.php?opc=%s' % [i]
page = Nokogiri::HTML(open(url))
page.css("select[name='CmbPartidos'] option").each do |option|
//valid value
if option["value"] != "0"
csv << [option["value"],option.content]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment