Created
December 5, 2014 02:09
-
-
Save mwhooker/234f21ce1436892168ac 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 'open-uri' | |
require 'nokogiri' | |
class Department | |
def initialize(department, classes) | |
@department = department | |
@classes = classes | |
end | |
def get_department() | |
@department.split(' ') | |
end | |
def get_classes() | |
@classes | |
end | |
end | |
def main | |
class_url = "https://www.ccsf.edu/Schedule/Fall/computer_science.shtml" | |
html = Nokogiri::HTML(open(class_url)) | |
departments = [] | |
department = nil | |
classes = [] | |
html.css("pre").children.each {|node| | |
if node.name == "h2" | |
if department != nil | |
departments << Department.new(department, classes) | |
department = nil | |
classes = [] | |
end | |
department = node.text | |
elsif node.name == "span" and node.attr(:class) == "courseTitle" | |
classes << node.text | |
end | |
departments << Department.new(department, classes) | |
} | |
departments.each {|dep| | |
puts dep.get_department | |
} | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment