Class: MovieHelper::Scraper
- Inherits:
-
Object
- Object
- MovieHelper::Scraper
- Defined in:
- lib/movie_helper/scraper.rb
Class Method Summary collapse
- .latest_amazon ⇒ Object
- .latest_elsewhere ⇒ Object
- .latest_netflix ⇒ Object
- .random ⇒ Object
- .scrape_movie(link, category) ⇒ Object
Class Method Details
.latest_amazon ⇒ Object
41 42 43 44 45 |
# File 'lib/movie_helper/scraper.rb', line 41 def self.latest_amazon doc = Nokogiri::HTML(open("https://agoodmovietowatch.com/all/?on=USA-amazon-prime&by=new")) links = doc.css("span.content-title").map {|movie| movie.css("a").first.first.last} best = links.map {|movie_link| scrape_movie(movie_link, "amazon")} end |
.latest_elsewhere ⇒ Object
47 48 49 50 51 |
# File 'lib/movie_helper/scraper.rb', line 47 def self.latest_elsewhere doc = Nokogiri::HTML(open("https://agoodmovietowatch.com/all/?by=new")) links = doc.css("span.content-title").map {|movie| movie.css("a").first.first.last} best = links.map {|movie_link| scrape_movie(movie_link, "elsewhere")} end |
.latest_netflix ⇒ Object
35 36 37 38 39 |
# File 'lib/movie_helper/scraper.rb', line 35 def self.latest_netflix doc = Nokogiri::HTML(open("https://agoodmovietowatch.com/all/?on=USA-netflix&by=new")) links = doc.css("span.content-title").map {|movie| movie.css("a").first.first.last} best = links.map {|movie_link| scrape_movie(movie_link, "netflix")} end |
.random ⇒ Object
31 32 33 |
# File 'lib/movie_helper/scraper.rb', line 31 def self.random scrape_movie("https://agoodmovietowatch.com/random/", nil) end |
.scrape_movie(link, category) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/movie_helper/scraper.rb', line 3 def self.scrape_movie(link, category) doc = Nokogiri::HTML(open(link)) hash = {} hash[:title] = doc.css("span.content-title").children.text.strip hash[:year] = doc.css("span.single-year").children.text.strip hash[:summary] = doc.css("div.wc-comment-text").children.text.strip hash[:genre] = doc.css("span[itemprop='genre']").children.text.strip if doc.css("div.infom span").count > 1 hash[:mood] = doc.css("div.infom span")[1].text.strip hash[:actors] = doc.css("div.infom span")[2].text.strip hash[:director] = doc.css("div.infom span")[3].text.strip hash[:language] = doc.css("div.infom span")[4].text.strip end hash[:url] = link if category == "netflix" hash[:is_netflix] = true elsif category == "amazon" hash[:is_amazon] = true elsif category == "elsewhere" hash[:is_elsewhere] = true end hash end |