- Parseo de dias en horario
- Parseo de fecha en horario
- Tolerancia a fallos cuando hay campos vacios
- Tal vez sea necesario que sean objetos??
-
-
Save huichops/f2a768ecd3a1e651984f to your computer and use it in GitHub Desktop.
Script para parsear ofertas del siiau
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
Script para sacar los datos de la oferta academica del SIIAU |
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' | |
def parse_profesor(element) | |
element.css('td').last.text | |
end | |
def parse_horario(element) | |
horarios_list = [] | |
keys = %w[hora dias edificio aula fecha] | |
horarios = element.css('tr') | |
horarios.each do |horario| | |
horario_hash = {} | |
campos = horario.children[1..-1] | |
keys.each_with_index do |val, index| | |
horario_hash[val.to_sym] = campos[index].text | |
end | |
horarios_list.push horario_hash | |
end | |
horarios_list | |
end | |
def parsiiau(html) | |
lista_ofertas = [] | |
keys = %w[nrc clave materia seccion creditos cupo disponible horario profesor] | |
ofertas = html.at_css('table').children[2..-1] | |
ofertas.each do |tr| | |
oferta = {} | |
campos = tr > 'td' | |
keys.each_with_index do |val, index| | |
if keys[index] == 'horario' | |
result = parse_horario campos[index] | |
elsif keys[index] == 'profesor' | |
result = parse_profesor campos[index] | |
else | |
result = campos[index].text | |
end | |
oferta[val.to_sym] = result | |
end | |
lista_ofertas.push oferta | |
end | |
lista_ofertas | |
end | |
# ejecutar ejemplo | |
#doc = Nokogiri::HTML.parse(open('http://t09.siiau.udg.mx/wco/sspseca.consulta_oferta?ciclop=201410&cup=D&mostrarp=5')) | |
#puts parsiiau doc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment