Skip to content

Instantly share code, notes, and snippets.

@edivandecastro
Last active March 15, 2016 02:05
Show Gist options
  • Save edivandecastro/1f84670dfd83bad950cd to your computer and use it in GitHub Desktop.
Save edivandecastro/1f84670dfd83bad950cd to your computer and use it in GitHub Desktop.
require "rubygems"
require "mechanize"
agent = Mechanize.new
page = agent.get("http://esaj.tjce.jus.br/cpopg/open.do")
form = page.form_with(:name => "consultarProcessoForm")
page.form_with(:name => "consultarProcessoForm") do |form|
form.fields.each do |field|
field.value = field.options.detect { |option| option.value == "NUMPROC"}.value if field.name == "cbPesquisa"
field.value = "0173241-19.2013" if field.name == "numeroDigitoAnoUnificado"
field.value = "0173241-19.2013.8.06.0001" if field.name == "dadosConsulta.valorConsultaNuUnificado"
field.value = "0001" if field.name == "foroNumeroUnificado"
end
end
form.radiobutton_with(:value => "UNIFICADO").check
page = form.submit
tables = page.parser.xpath("//table[@class='secaoFormBody']")
classe = tables[1].css("tr td")[5].children[1].children[1].text.gsub(/(\t)|(\n)/, "").strip
area = tables[1].css("tr td")[8].children.last.text.gsub(/(\t)|(\n)/, "").strip
assunto = tables[1].css("tr td")[10].text.gsub(/(\t)|(\n)/, "").strip
distribuição1 = tables[1].css("tr td")[12].css('span').text
distribuição2 = tables[1].css("tr td")[14].css('span').text
controle = tables[1].css("tr td")[16].css('span').text
juiz = tables[1].css("tr td")[18].css('span').text
valor_acao = tables[1].css("tr td")[20].css('span').text
tables = page.parser.css("table#tableTodasPartes")
requeridos = []
requerentes = []
tables[0].css('tr').each do |tr|
if tr.css('td')[0].children.children.text.strip == "Requerente: "
requerentes << tr.css('td')[1].text.gsub(/(\t)|(\n)/, "").strip
end
if tr.css('td')[0].children.children.text.strip == "Requerido: "
requerido = tr.css('td')[1].text.gsub(/(\t)|(\n)/, "").strip
if requerido.include?("Advogada:")
requeridos << requerido.split("Advogada:").first
elsif requerido.include?("Advogado:")
requeridos << requerido.split("Advogado:").first
else
requeridos << requerido
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment