Skip to content

Instantly share code, notes, and snippets.

@srawlins
Created May 29, 2013 22:01
Show Gist options
  • Select an option

  • Save srawlins/5674194 to your computer and use it in GitHub Desktop.

Select an option

Save srawlins/5674194 to your computer and use it in GitHub Desktop.
require "mechanize"
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
a.get("https://www.google.com/") do |page|
puts page.at("#gbqfq").inspect
end
require "mechanize"
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
a.get("https://www.google.com/") do |page|
search_result = page.form_with(:name => 'gbqf') do |search|
search.q = 'Hello world'
end.submit
search_result.search("#res div.rc").each do |res|
puts "#{res.at("h3 >a").text} <#{res.at("cite").text}>"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment