Skip to content

Instantly share code, notes, and snippets.

@agilous
Created October 24, 2011 01:43
Show Gist options
  • Save agilous/1308201 to your computer and use it in GitHub Desktop.
Save agilous/1308201 to your computer and use it in GitHub Desktop.
Parser for the BPA Competitive Event List
#!/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