Skip to content

Instantly share code, notes, and snippets.

@lucianokrebs
Forked from anonymous/scraping.rb
Created July 5, 2017 11:32
Show Gist options
  • Save lucianokrebs/741457fdda7912ab2eb4d1544cd8fec7 to your computer and use it in GitHub Desktop.
Save lucianokrebs/741457fdda7912ab2eb4d1544cd8fec7 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
servidores = []
servidores_sem_salário = []
(1..5).each do |page|
url = "http://www.portaltransparencia.gov.br/servidores/OrgaoExercicio-ListaServidores.asp?CodOrg=25201&Pagina=#{page}"
raw_html = open(url).read
html = Nokogiri::HTML(raw_html)
html.search("#listagem table td:nth-child(2) a").each do |servidor|
name = servidor.text.strip
path = servidor.attr("href")
url = "http://www.portaltransparencia.gov.br/servidores/#{path}"
raw_html = open(url).read
html = Nokogiri::HTML(raw_html)
link_da_remuneracao = html.search("#resumo a")[0]
path = link_da_remuneracao.attr("href")
url = "http://www.portaltransparencia.gov.br#{path}"
raw_html = open(url).read
html = Nokogiri::HTML(raw_html)
salário = html.search(".remuneracaolinhatotalliquida .colunaValor")[0]
print "="
if salário
servidores << { name: name, salary: salário.text }
else
servidores_sem_salário << name
end
end
end
puts
puts "Servidores:"
servidores.each do |servidor|
puts "#{servidor[:name]} - #{servidor[:salary]}"
end
puts
puts "Servidores sem salário:"
puts servidores_sem_salário
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment