class Scraper
Attributes
doc[RW]
Public Class Methods
new()
click to toggle source
# File lib/nyt_bestsellers_cli_gem/scraper.rb, line 9 def initialize @doc = Nokogiri::HTML(open("https://www.nytimes.com/books/best-sellers/")) end
Public Instance Methods
scrape()
click to toggle source
# File lib/nyt_bestsellers_cli_gem/scraper.rb, line 13 def scrape scrape_category_name scrape_book_details end
scrape_book_details()
click to toggle source
# File lib/nyt_bestsellers_cli_gem/scraper.rb, line 25 def scrape_book_details @doc.css("section.subcategory").each do |section| category = section.css("a.subcategory-heading-link").text.strip section.css("li.trending").each do |bestseller| title = bestseller.css("h3.title").text author = bestseller.css("p.author").text.gsub("by ", "") summary = bestseller.css("p.description").text Book.new(title, author, summary, category) end end end
scrape_category_name()
click to toggle source
# File lib/nyt_bestsellers_cli_gem/scraper.rb, line 18 def scrape_category_name @doc.css("section.subcategory").each do |section| name = section.css("a.subcategory-heading-link").text.strip Category.new(name) end end