Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created December 5, 2009 19:19
Show Gist options
  • Select an option

  • Save Sixeight/249817 to your computer and use it in GitHub Desktop.

Select an option

Save Sixeight/249817 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'rubygems'
require 'mechanize'
def google(query)
agent = WWW::Mechanize.new
agent.get 'http://www.google.com'
agent.page.form_with(:name => 'f') do |form|
form.field_with(:name => 'q').value = query
form.click_button
end
agent.page
end
puts google('2 * 5').at('h2').content
#=> 2 * 5 = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment