Skip to content

Instantly share code, notes, and snippets.

@naoranger
Created August 9, 2012 03:08
Show Gist options
  • Select an option

  • Save naoranger/3300567 to your computer and use it in GitHub Desktop.

Select an option

Save naoranger/3300567 to your computer and use it in GitHub Desktop.
mechanize sample google
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
uri = URI.parse('http://google.com/')
page = agent.get(uri)
sbox = page.form_with(name: 'gbqf')
sbox.q = 'crucial ssd'
result = agent.submit(sbox)
result.search(".//a[@class='l']").each_with_index.map do |link, i|
puts "#{i} #{link.content}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment