Skip to content

Instantly share code, notes, and snippets.

@GBH
Created March 28, 2010 17:39
Show Gist options
  • Save GBH/346896 to your computer and use it in GitHub Desktop.
Save GBH/346896 to your computer and use it in GitHub Desktop.
#!/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