Class: Catpedia::Scraper
- Inherits:
-
Object
- Object
- Catpedia::Scraper
- Defined in:
- lib/catpedia/scraper.rb
Constant Summary collapse
- URL =
"http://www.vetstreet.com/cats/breeds"
Class Method Summary collapse
-
.scrape_cat_details(url) ⇒ Object
return hash of details for a single cat.
-
.scrape_cats ⇒ Object
return array of all cat objects, each with detailed attributes.
Class Method Details
.scrape_cat_details(url) ⇒ Object
return hash of details for a single cat
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/catpedia/scraper.rb', line 15 def self.scrape_cat_details(url) #return hash of details for a single cat cat = {} page = Nokogiri::HTML(open(url)) cat[:name] = page.css(".breed-detail h1").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat[:summary] = page.css("#breed-detail p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat[:history] = page.css("#history .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat[:personality] = page.css("#personality .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat[:health] = page.css("#health .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat[:grooming] = page.css("#grooming .richtext p").text.strip.gsub("\t","").gsub("\r","").gsub("\n","") cat end |
.scrape_cats ⇒ Object
return array of all cat objects, each with detailed attributes
5 6 7 8 9 10 11 12 13 |
# File 'lib/catpedia/scraper.rb', line 5 def self.scrape_cats #return array of all cat objects, each with detailed attributes cat_urls = Nokogiri::HTML(open(URL)).css("#hub-breed-list-container ul li a") cat_urls.each do |e| url = "http://www.vetstreet.com/" + e.attr('href') cat_details_hash = scrape_cat_details(url) Catpedia::Cat.new(cat_details_hash) end Catpedia::Cat.all end |