Class: IndoorJungle::Scraper
- Inherits:
-
Object
- Object
- IndoorJungle::Scraper
- Defined in:
- lib/indoor_jungle/scraper.rb
Overview
Scraper.scrape_site(‘www.plants.com/c/all-plants’) Scraper.scrape_plant(‘www.plants.com/p/snake-plant-157646?c=all-plants’)
Class Method Summary collapse
-
.scrape_plant(plant_url) ⇒ Object
here lies my mess.
- .scrape_site(site) ⇒ Object
Class Method Details
.scrape_plant(plant_url) ⇒ Object
here lies my mess
19 20 21 22 23 24 25 26 27 |
# File 'lib/indoor_jungle/scraper.rb', line 19 def self.scrape_plant(plant_url) page = Nokogiri::HTML(URI.open(plant_url)) plant = {} element = page.css('div.product-layout-') plant[:sunlight] = element.css('p.condition-text.mb-0').first.text, plant[:water] = element.css('div.image-card p')[1].text, plant[:temperature] = element.css('div.image-card p')[2].text.delete("\u00B0F") plant #currently this whole hash is being applied to sunlight end |
.scrape_site(site) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/indoor_jungle/scraper.rb', line 5 def self.scrape_site(site) page = Nokogiri::HTML(URI.open(site)) plants_lumped = [] page.css('div.ProductList_productItem__HxDc2').each do |plants| plants_lumped << { :name => plants.css('div.col-12').text, :price_range => plants.css("a span").children[1].text, :plant_url => "https://www.plants.com" + (plants.css("a")[0].attributes["href"].value) } end plants_lumped end |