class NYTBestsellers::Scraper
Public Class Methods
get_date()
click to toggle source
# File lib/nytimes/scraper.rb, line 43 def self.get_date get_page.css("div.date-range").text.strip end
get_genre_pages()
click to toggle source
# File lib/nytimes/scraper.rb, line 16 def self.get_genre_pages agent = Mechanize.new NYTBestsellers::Genre.all.collect do |genre| page = agent.get("#{genre.url}") end end
get_page()
click to toggle source
# File lib/nytimes/scraper.rb, line 3 def self.get_page @@page ||= Mechanize.new.get("http://www.nytimes.com/books/best-sellers/") end
make_books()
click to toggle source
# File lib/nytimes/scraper.rb, line 23 def self.make_books get_genre_pages.each do |page| book_genre = page.css("section h2")[0].text books = page.css("ol")[0].css("li article a") books.each do |book| if book.css("p")[1] != nil && book.css("p")[1].attribute("itemprop").value == "author" NYTBestsellers::Book.new({ genre: book_genre, title: book.css("h3").text.split.collect(&:capitalize).join(" "), author: book.css("p")[1].text.split.delete_if{|x| x == "by"}.join(" "), publisher: book.css("p")[2].text, wol: book.css("p")[0].text, summary: book.css("p")[3].text }) end end end end
make_genres()
click to toggle source
# File lib/nytimes/scraper.rb, line 7 def self.make_genres get_page.css("section h2").each do |category| NYTBestsellers::Genre.new({ name: category.css("a").text.strip, url: "http://www.nytimes.com#{category.css("a").attr("href").text}" }) end end