Class: BestReads::Scraper

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

Constant Summary collapse

BASE_PATH =
"https://www.goodreads.com"

Class Method Summary collapse

Class Method Details

.scrape_best_of_listsObject



3
4
5
6
7
8
9
10
11
# File 'lib/best_reads/scraper.rb', line 3

def self.scrape_best_of_lists
  doc = Nokogiri::HTML(open("#{BASE_PATH}/list"))
  list_details = []
  lists = doc.css(".rightContainer .bigBoxContent").first.css("a.listTitle")
  lists.each do |list|
    list_details << {name: list.text, url: list["href"]}
  end
  list_details
end

.scrape_books_by_list(books_url) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/best_reads/scraper.rb', line 13

def self.scrape_books_by_list(books_url)
  doc = Nokogiri::HTML(open("#{BASE_PATH}/#{books_url}"))
  book_details = []
  book_table = doc.css("#all_votes td:nth-child(3)")
  puts "book_table: #{book_table.size}"
  book_table.each do |book_detail|
    title_and_url = book_detail.css("a.bookTitle")
    book_details << {title: title_and_url.css("span").text,
                      url: title_and_url.attr("href").text,
                      author: book_detail.css("a.authorName").text,
                      rating: book_detail.css("span.minirating").text}
  end
  book_details

end