Class: DayBooks::Scraper
- Inherits:
-
Object
- Object
- DayBooks::Scraper
- Defined in:
- lib/scraper.rb
Constant Summary collapse
- @@books_array =
[]
Instance Attribute Summary collapse
-
#books_array ⇒ Object
Returns the value of attribute books_array.
Class Method Summary collapse
- .books_array ⇒ Object
- .empty_books_array ⇒ Object
- .get_book_info ⇒ Object
- .get_description(book_url) ⇒ Object
- .get_page(page_url) ⇒ Object
Instance Attribute Details
#books_array ⇒ Object
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_array ⇒ Object
8 9 10 |
# File 'lib/scraper.rb', line 8 def self.books_array @@books_array end |
.empty_books_array ⇒ Object
12 13 14 |
# File 'lib/scraper.rb', line 12 def self.empty_books_array @@books_array.clear end |
.get_book_info ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/scraper.rb', line 20 def self.get_book_info = "https://www.goodreads.com/author/list/19823.Sylvia_Day?page=1&per_page=99999" book_info = self.get_page().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 |