我正在从两个站点抓取数据。首先刮擦其他,然后将价格重复两次。第二个站点抓取了正确的数据,但是返回了一个间距问题,我不确定该如何解决。
class DailyDealz::Deal
attr_accessor :name, :price, :availability, :url
def self.today
# Scrape woot and meh and then return deals based on that data
self.scrape_deals
end
def self.scrape_deals
deals = []
deals << self.scrape_woot
deals << self.scrape_meh
# deals << self.scrape_steepandcheap
deals
end
def self.scrape_woot
doc = Nokogiri::HTML(open("https://www.woot.com/"))
deal = self.new
deal.name = doc.search("h2.main-title").text.strip
deal.price = doc.search("#todays-deal span.price").text.strip
deal.url = doc.search("a.wantone").first.attr("href").strip
deal.availability = true
deal.website
deal
end
def self.scrape_meh
doc = Nokogiri::HTML(open("https://meh.com/"))
deal = self.new
deal.name = doc.search("section.features h2").text.strip
deal.price = doc.search("#button.buy-button").text.gsub("Buy it.", "").strip
deal.url = "https://meh.com/"
deal.availability = true
deal
end
返回此:
// ♥ ./bin/daily-dealz
Todays Daily Deals
1. Apple Watch Blowout! - $129.99–$279.99$129.99$279.99 - true -
2. 12-For-Tuesday: Fun Putty 1.8oz Tins
- 12 for $19 - - true -
Enter the number of the deal you'd like more info on or type list to see deals again or exit to exit
program.
我该如何删除重复的定价和不足的间隔?