Class: FreshTomatoes::Scraper
- Inherits:
-
Object
- Object
- FreshTomatoes::Scraper
- Defined in:
- lib/fresh_tomatoes/scraper.rb
Constant Summary collapse
- @@url =
"https://www.rottentomatoes.com/top/bestofrt/"
Class Method Summary collapse
Class Method Details
.scrape_details(movie) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/fresh_tomatoes/scraper.rb', line 15 def self.scrape_details(movie) pg = Nokogiri::HTML(open(movie.url)) movie.description = pg.css("div#movieSynopsis").text.strip movie.audience_score = pg.css("div.audience-score span.mop-ratings-wrap__percentage").text.strip movie. = pg.css("div:contains('Rating')+div.meta-value").text.strip movie.runtime = pg.css("div:contains('Runtime')+div time").text.strip end |
.scrape_movies ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/fresh_tomatoes/scraper.rb', line 4 def self.scrape_movies pg = Nokogiri::HTML(open(@@url)) movies = pg.css("table#Top-Box-Office tr.sidebarInTheaterOpening") movies.each do |m| title = m.css("td.middle_col").text.strip tomatometer = m.css("span.tMeterScore").text url = "https://www.rottentomatoes.com"+m.css("a").attribute("href").value FreshTomatoes::Movie.new(title, url, tomatometer) end end |