class NYTFiction::Scraper

Public Class Methods

scrape_books() click to toggle source
# File lib/nyt_fiction/scraper.rb, line 3
def self.scrape_books
  url = open("http://www.nytimes.com/books/best-sellers/combined-print-and-e-book-fiction", :allow_redirections => :all)
  page = Nokogiri::HTML(url.read)
  page.encoding = 'utf-8'
  page.css(".book-body").each do |b|
    book = NYTFiction::Book.new
    book.title = b.css("h2.title").text.split.map {|w| w.capitalize}.join(" ")
    book.author = b.css(".author").text
    book.publisher = b.css(".publisher").text
    book.description = b.css(".description").text.strip
    book.freshness = b.css(".freshness").text
    book.save
  end
end