require 'rubygems' require 'open-uri' require 'hpricot' q = "user_query" url = "http://www.google.com/search?q=#{q}" doc = Hpricot(open(url).read) first_url = (doc/"div[@class='g'] a").first["href"] puts "This is the numer one result in google" puts first_url puts "\n\r This is the google search url" puts url