Created
March 28, 2010 17:39
-
-
Save GBH/346896 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'pp' | |
doc = Nokogiri::HTML(open('http://www.ibao.org/html/find_a_broker/mapfind.asp?tcode=13')) | |
out = [] | |
doc.search('div.SubTitle').each do |name| | |
broker = { } | |
broker[:name] = name.content | |
has_automotive = false | |
div = name | |
while div = div.next_element do | |
broker[:email] = div.content if div.content[/.*@.*/] | |
broker[:site] = div.content if div.content[/(^[^@]*)\.(net|ca|com)/] | |
broker[:phone] = div.content if div.content[/\(\d{3}\)\s\d{3}-\d{4}/] | |
has_automotive = !div.content[/Automobile/].nil? unless has_automotive | |
end | |
out << broker if has_automotive | |
end | |
out.each do |line| | |
puts "#{line[:name]}, #{line[:site]}, #{line[:phone]}, #{line[:email]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment