Skip to content

Instantly share code, notes, and snippets.

@toroidal-code
Created August 14, 2013 21:23
Show Gist options
  • Save toroidal-code/6235807 to your computer and use it in GitHub Desktop.
Save toroidal-code/6235807 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
def next_node_with(current, attribute, cond)
while current && current.send(attribute) != cond
current = current.next
end
current
end
doc = Nokogiri::HTML(open('http://www.rit.edu/fa/diningservices/content/hours-operation'))
doc.css('h3 a').each do |node|
if node.content == "" && node['id'] == node['name']
puts node
table = next_node_with(node.parent, :name, "table")
rows = table.search('tr')[1..-1]
details = rows.collect do |row|
row.search('td//text()').collect{|text| text.to_s.strip}
end
puts details
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment