Sha256: 8bbd727d213d7ec2e04aceb7e60c712ca01370ecb041d53122d740dd23a73911
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
require_relative 'CigarFreaksEnvironment.rb' class CigarScraper attr_accessor :doc def initialize url = "https://www.cigaraficionado.com/ratingsandreviews" @doc ||= Nokogiri::HTML(open(url)) end def get_names names = @doc.css("div.cigar-teaser_wrapper h3").map {|name| name.text}.compact end def get_points counter = 10 while counter <= 10 do counter += 1 points = @doc.css("div.cigar-teaser_wrapper div.cigar-teaser_info div.cigar-teaser_score").map {|points| points.text}.compact end points end def hyperlink(input) prefix = "https://www.cigaraficionado.com" suffix = @doc.search("div.cigar-teaser_wrapper a[href]").map do |link| link.attribute("href").value end "#{prefix}#{suffix[input]}" end def run scraper = CigarScraper.new names = scraper.get_names points = scraper.get_points (0...names.size).each do |index| puts "- - - - - -".red puts "#{names[index]} | Points: #{points[index]}".blue end end def scrape_details(url) @d = Nokogiri::HTML(open(url)) params = {} specs = @d.search("tbody td").map do |info| info.text end params[:tasting_note] = specs[0].strip params[:body] = specs[2].strip params[:size] = specs[4].strip params[:ring_gauge] = specs[6].strip params[:length] = specs[8].strip params[:filler] = specs[10].strip params[:binder] = specs[12].strip params[:wrapper] = specs[14].strip params[:price] = specs[18].strip Cigars.new(params) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
CigarFreaks-0.1.1 | lib/CigarScraper.rb |
CigarFreaks-0.1.0 | lib/CigarScraper.rb |