18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/scraper.rb', line 18
def self.scrape_pet_profile(url)
pet_profile_details = {}
pet_profile = "http://bestfriends.org" + url
doc = Nokogiri::HTML(open(pet_profile))
pet_items = doc.css("div.rescue-groups-pet-info-item")
pet_items.each do |attribute|
if attribute.css("span.gray").text == "Size:"
pet_profile_details[:size] = attribute.css("span.bold.black").text
elsif attribute.css("span.gray").text == "Color:"
pet_profile_details[:color] = attribute.css("span.bold.black").text
elsif attribute.css("span.gray").text == "Sex:"
pet_profile_details[:sex] = attribute.css("span.bold.black").text
end
end
pet_profile_details[:description] = doc.css("section.rescue-groups-pet-info-section p").text.gsub("\n ", "")
pet_profile_details
end
|