Created
August 14, 2013 21:23
-
-
Save toroidal-code/6235807 to your computer and use it in GitHub Desktop.
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 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