Created
March 6, 2012 23:04
-
-
Save maheshmurthy/1989626 to your computer and use it in GitHub Desktop.
click on all links in the site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
def click_links(page, link_store) | |
page.links.each do |link| | |
text = link.text.strip | |
next unless text.length > 0 | |
puts "#{text} #{link.href} #{link_store.length}" | |
unless link_store[text] | |
begin | |
page = link.click | |
rescue => e | |
link_store[text] = link | |
puts "Failed page load for #{link.inspect}: #{e.message}" | |
next | |
end | |
link_store[text] = link | |
link_store = click_links(page, link_store) | |
end | |
end | |
link_store | |
end | |
a = Mechanize.new | |
link_store = {} | |
my_page = nil | |
a.get('http://<APP_NAME>.dev/login') do |page| | |
# Submit the login form | |
my_page = page.form_with(:action => 'http://<APP_NAME>.dev/login') do |f| | |
f.email = "<email>" | |
f.password = "<password>" | |
end.click_button | |
end | |
link_store = click_links(my_page, link_store) | |
my_page.links.each do |link| | |
link_store = click_links(link, link_store) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment