Skip to content

Instantly share code, notes, and snippets.

@hpneo
Created November 20, 2020 17:57
Show Gist options
  • Save hpneo/d818fc21a14339447ae7889dd2396ff9 to your computer and use it in GitHub Desktop.
Save hpneo/d818fc21a14339447ae7889dd2396ff9 to your computer and use it in GitHub Desktop.
Partidos políticos inscritos
source "https://rubygems.org"
ruby "2.7.2"
gem "scrap_kit"
gem "active_worksheet"
gem "dry-cli"
gem "tty-table"
require "scrap_kit"
require "tty-table"
recipe = ScrapKit::Recipe.load(
url: "https://aplicaciones007.jne.gob.pe/srop_publico/Consulta/OrganizacionPolitica",
steps: [
{
fill_form: {
"#IDESTADOOP": "Inscrito"
}
},
{
click: {
css: ".col-sm-3 input[type=button]"
}
}
],
attributes: {
organizaciones: {
selector: "#tblOrganizacionPolitica > tbody > tr",
children_attributes: {
logo: "td:nth-child(2) > div > img",
nombre: "td:nth-child(2) > span:nth-child(2)",
fecha_inscripcion: "td:nth-child(2) > span:nth-child(4)",
website: "td:nth-child(3) > address > div:nth-child(3) > div.col-md-11",
}
}
}
)
output = recipe.run
# Prepare the table in ASCII format
output[:organizaciones] = output[:organizaciones].map do |item|
item[:fecha_inscripcion] = item[:fecha_inscripcion].split(" ").last
item
end
headers = ["Nombre", "Fecha de inscripción", "Website"]
results = output[:organizaciones].map do |item|
[item[:nombre], item[:fecha_inscripcion], item[:website]]
end
table = TTY::Table.new(headers, results)
renderer = TTY::Table::Renderer::ASCII.new(table)
puts table.render(:ascii, padding: [0, 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment