Sha256: 534d6a3744591506bcc91272b8bc9a44a5910970add6429e9e2fa66150a8ef3d

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'nokogiri'
require 'open-uri'

module CoffeeBreak
    class Scraper 

        def scrape
            doc = Nokogiri::HTML(URI.open("https://playeronecoffee.com/collections/all-coffee/"))

            doc.css(".grid-view-item").each do |tag| # Access each tag from below.
                
                name = tag.css(".grid-view-item__title").text.upcase # Text in UPPERCASE letters.
                label = tag.css("div.grid-view-item__level span.label").text.upcase # CSS Selector searches document, looking for desired Div classes.
                price = tag.css("div.grid-view-item__meta span.product-price__price").text # Displays price per specific product.
                link = "https://playeronecoffee.com"+ tag.css("a.grid-view-item__link")[0][:href] # Grabs href to iterate through product links.
                details = Nokogiri::HTML(URI.open(link)).css("div.product-single__description p").text # Opens product link to provide details.
                
                product = Beans.new(name, label, price, details) 
                # Puts all scraped data tags to Beans format.

                Beans.all << product 
                # Stores scraped data onto Beans class.

            end
        end

    end 
end 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coffeebreak-0.1.0 lib/scraper.rb