Class: BestNovels::Scraper

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

Class Method Summary collapse

Class Method Details

.scrape_novelsObject

class method



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

def self.scrape_novels
  site = "https://www.theguardian.com/books/2015/aug/17/the-100-best-novels-written-in-english-the-full-list"
  doc = Nokogiri::HTML(open(site))
  novels = doc.css("div.content__article-body.from-content-api.js-article__body p strong")
  novels.each do |n|
    title = n.css("a.u-underline").text.strip
    url = n.css("a").attr("href").value
    BestNovels::Novel.new(title, url)
 end
end

.scrape_review(novel) ⇒ Object

class method



15
16
17
18
19
20
21
# File 'lib/best_novels/scraper.rb', line 15

def self.scrape_review(novel)
    url = "#{novel.url}"
    doc = Nokogiri::HTML(open(url))
    doc.css("div.content__article-body.from-content-api.js-article__body p:first-of-type").each do |paragraph|
    novel.review = paragraph.text.strip
  end
end