Created
October 24, 2011 01:43
-
-
Save agilous/1308201 to your computer and use it in GitHub Desktop.
Parser for the BPA Competitive Event List
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'open-uri' | |
def parse_event_number_and_name(text) | |
number, name = $1, $2 if text =~ /\(([a-zA-Z0-9]+)\)\s(.*):/ | |
end | |
doc = Nokogiri::HTML(open('http://www.bpa.org/compete/eventlist')) | |
maincontent = doc.xpath('id("maincontent")') | |
siblings_array = maincontent.xpath('//br/following-sibling::*|//br/preceding-sibling::*').to_a | |
siblings_array.each do |sibling| | |
number, name = parse_event_number_and_name(sibling.content) | |
puts "[#{number}] #{name}" if number && name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment