Sha256: 1b1093a5af9063c1e7c4dccf22b82d3d9fbdcbb554c73ae8fcf7ec87b71b0c25

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

class NewMovies::Scraper

  def self.scrape_coming_soon_movies
    doc = Nokogiri::HTML(open("https://www.cinemark.com/movies/coming-soon"))
    movie_collection = []
    doc.css("div.card .title").collect do |new_movie|
      movie_collection << {:title => new_movie.inner_text,
                          :url => "https://www.cinemark.com#{new_movie.attribute("href").value}"}
    end
    movie_collection
  end

  def self.scrape_movie_details(movie)
    doc = Nokogiri::HTML(open("#{movie.url}"))
    attribute_values ={}
    attributes = {"Release Dates" => "release_date", "Rating" => "rating", "Runtime" => "runtime", "Genre" => "genre", "Cast" => "cast", "Director" => "director", "Synopsis" => "synopsis"}
    attributes.each do |attribute, v|
      if doc.xpath("//h3[contains(text(), '#{attribute}')]").text.include?("#{attribute}")
         attribute_values[[attributes[attribute]].join.to_sym] = doc.xpath("//h3[contains(text(), '#{attribute}')]/following-sibling::p")[0].text.strip
      end
      if doc.xpath("//h3[contains(text(), 'Official Site')]").text.strip.include?("Official Site")
        attribute_values["movie_site"] = doc.css("p.trunc").text.strip
      end
    end
    attribute_values
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
new_movies_cinemark-0.1.11 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.10 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.9 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.8 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.7 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.6 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.5 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.4 lib/new_movies/cinemark_scraper.rb
new_movies-0.1.3 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.2 lib/new_movies/cinemark_scraper.rb
new_movies_cinemark-0.1.1 lib/new_movies/cinemark_scraper.rb
new_movies-0.1.0 lib/new_movies/cinemark_scraper.rb