Skip to content

Instantly share code, notes, and snippets.

@mwhooker
Created December 5, 2014 02:09
Show Gist options
  • Save mwhooker/234f21ce1436892168ac to your computer and use it in GitHub Desktop.
Save mwhooker/234f21ce1436892168ac to your computer and use it in GitHub Desktop.
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