Skip to content

Instantly share code, notes, and snippets.

@7hunderbird
Created December 9, 2011 20:29
Show Gist options
  • Select an option

  • Save 7hunderbird/1453166 to your computer and use it in GitHub Desktop.

Select an option

Save 7hunderbird/1453166 to your computer and use it in GitHub Desktop.
This will take a UPC number and return the Title.
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