Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Created June 3, 2012 12:34
Show Gist options
  • Save timothyklim/2863293 to your computer and use it in GitHub Desktop.
Save timothyklim/2863293 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'json'
require 'uri'
KEY = ''
def get_results query, pages = 1
result = []
pages.times do |page|
data = open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=#{KEY}&q=#{URI.encode(query)}&start=#{page}&rsz=8").read
result << JSON.parse(data)['responseData']['results']
end
result.flatten(1)
end
puts get_results('Timothy Klim', 10).map { |r| r['title'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment