8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/love_of_tea/scraper.rb', line 8
def self.scrape_by_tea_url(tea_url)
doc = Nokogiri::HTML(open(tea_url))
teas = []
doc.css(".product.clearfix").each do |tea|
price = tea.css("div.col-xs-12.col-sm-6 div.price.text-center").text.strip.gsub(/\s+/,'')
price2 = tea.css("div.col-sm-6.mar_btm div.col-sm-12 .price").text.strip.gsub(/\s+/,'')
tea_hash = {:name => tea.css("h3").text,
:description => tea.css("div.short-desc").text,
:price => price,
:price2 => price2,
:type => doc.css("header h1").text,
:url => "https://www.rishi-tea.com" + tea.css("a").attribute("href").value}
teas << tea_hash
end
teas.each do |teahash|
teahash.delete_if {|key, value| value == nil || value == ""}
end
teas
end
|