Class: Bestsellers::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/bestsellers/scraper.rb

Class Method Summary collapse

Class Method Details

.create_bestsellersObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bestsellers/scraper.rb', line 11

def self.create_bestsellers
    doc = Nokogiri::HTML(open("https://www.barnesandnoble.com/b/books/_/N-1fZ29Z8q8"))
    books = doc.css("ol.product-shelf-list.product-list-view li")
    books.each do |book| 
        title = book.css("h3.product-info-title a").text.strip
        author = book.css("div.product-shelf-author a").text.strip
        price = book.css("a.current").text.strip
        url = "https://www.barnesandnoble.com" + book.css("h3.product-info-title a").attr("href")
        Bestsellers::Books.new(title, author, price, url)
    end
end

.todays_bestsellersObject



7
8
9
# File 'lib/bestsellers/scraper.rb', line 7

def self.todays_bestsellers
    self.select_bestsellers
end