Created
February 16, 2015 22:29
-
-
Save antoniocuga/7822715e07364d9580c7 to your computer and use it in GitHub Desktop.
Extract all politicians groups
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 '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