Class: DayBooks::Scraper

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

Constant Summary collapse

@@books_array =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#books_arrayObject

Returns the value of attribute books_array.



5
6
7
# File 'lib/scraper.rb', line 5

def books_array
  @books_array
end

Class Method Details

.books_arrayObject



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

def self.books_array
  @@books_array
end

.empty_books_arrayObject



12
13
14
# File 'lib/scraper.rb', line 12

def self.empty_books_array
  @@books_array.clear
end

.get_book_infoObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/scraper.rb', line 20

def self.get_book_info
  author_library_url = "https://www.goodreads.com/author/list/19823.Sylvia_Day?page=1&per_page=99999"
  book_info = self.get_page(author_library_url).css('tr[itemtype="http://schema.org/Book"]')
  book_info.each do |book|
    @@books_array << {
      :title => book.css('.bookTitle span[itemprop=name]').text,
      :book_url => book.css('a').attribute('href').value
    }
  end
end

.get_description(book_url) ⇒ Object



31
32
33
34
35
36
# File 'lib/scraper.rb', line 31

def self.get_description(book_url)
  full_book_url = "https://www.goodreads.com" + book_url
  doc = self.get_page(full_book_url)
  book_description = doc.css('div#descriptionContainer span[2]').text
  book_description
end

.get_page(page_url) ⇒ Object



16
17
18
# File 'lib/scraper.rb', line 16

def self.get_page(page_url)
  Nokogiri::HTML(open(page_url))
end