Skip to content

Instantly share code, notes, and snippets.

@ianbishop
Created July 18, 2012 13:57
Show Gist options
  • Select an option

  • Save ianbishop/3136361 to your computer and use it in GitHub Desktop.

Select an option

Save ianbishop/3136361 to your computer and use it in GitHub Desktop.
yellow page email scrp
class YellowPagesCrawler < Pioneer::Base
attr_reader :locations
def initialize(opts = {})
@locations_business = opts.fetch(:locations, {})
@locations = @locations_business.keys
super
end
def processing(req)
htmldoc = Nokogiri::HTML(req.response_body)
htmldoc.css('.busCardLeftLinks a').each do |a|
if a.content.strip == "Email"
business_details = @locations_business[req.url]
email = a[:title].strip
puts "Found email for: #{business_details} (#{email})"
contact = Contact.new
contact.province = business_details[0]
contact.city = business_details[1]
contact.name = business_details[2]
contact.country = "Canada"
contact.email = email
contact.source = "YP"
contact.save
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment