Skip to content

Instantly share code, notes, and snippets.

@dtolj
Created September 2, 2009 02:48
Show Gist options
  • Save dtolj/179517 to your computer and use it in GitHub Desktop.
Save dtolj/179517 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'uri'
require 'net/http'
require 'open-uri'
require 'rubygems'
require 'nokogiri'
require 'mechanize'
a = WWW::Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get("http://www.google.ca") do |page|
search_result = page.form_with(:name => 'f') do |search|
search.field_with(:name=>'q').value = my_val.to_s #options[:page]
end.submit
search_result.links.each do |link|
link = URI.extract(link.href.to_s,['http'])
puts link
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment