Created
December 9, 2011 20:29
-
-
Save 7hunderbird/1453166 to your computer and use it in GitHub Desktop.
This will take a UPC number and return the Title.
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 'nokogiri' | |
| require 'open-uri' | |
| puts "Give me a UPC code:" | |
| upc = gets.chomp | |
| url = "http://www.upcdatabase.com/item/" + upc | |
| doc = Nokogiri::HTML(open(url)) | |
| table_data = Array.new | |
| doc.css("tr td").each do |item| | |
| table_data << item | |
| end | |
| title = table_data[8] | |
| if title | |
| puts title.inner_html | |
| else | |
| puts "No results found, try again." | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment