Skip to content

Instantly share code, notes, and snippets.

@adacosta
Created February 8, 2011 05:09
Show Gist options
  • Save adacosta/815897 to your computer and use it in GitHub Desktop.
Save adacosta/815897 to your computer and use it in GitHub Desktop.
search
require 'nokogiri'
require 'open-uri'
require 'uri'
def search(query_string)
Nokogiri::HTML(open("http://www.google.com/search?q=#{URI.encode(query_string)}"))
.css("h3[class=r] a").map {|node| {:url => node["href"], :title => node.inner_html} }
end
puts search('ruby')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment