Created
March 3, 2010 01:31
-
-
Save vinbarnes/320201 to your computer and use it in GitHub Desktop.
retrieve movie info from imdb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'open-uri' | |
| require 'nokogiri' | |
| require 'uri' | |
| require 'pp' | |
| # find movie in imdb | |
| search_strings = ["commando", "from russia with love"] | |
| search_strings.each do |search| | |
| search_url = URI.escape("http://www.imdb.com/find?s=tt&q=#{search}") | |
| html_doc = Nokogiri::HTML(open(search_url)) | |
| pp html_doc.at_css("table:nth-child(7) tr:nth-child(1) a").attribute('href').value | |
| end | |
| # retrieve movie poster, year, rating, plot summary | |
| imdb_urls = %w[http://www.imdb.com/title/tt0088944/ http://www.imdb.com/title/tt0057076/] | |
| imdb_urls.each do |url| | |
| html_doc = Nokogiri::HTML(open(url)) | |
| puts | |
| puts 'poster' | |
| pp html_doc.at_css("#tn15lhs img").attribute('src').value | |
| puts 'year' | |
| pp html_doc.at_css(":nth-child(12) .info-content").children.first.text.strip | |
| puts 'rating' | |
| pp html_doc.at_css("#tn15rating b").children.first.text | |
| puts 'plot summary' | |
| pp html_doc.at_css(":nth-child(15) .info-content").children.first.text | |
| pp url + 'plotsummary' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment