Skip to content

Instantly share code, notes, and snippets.

@rob-mcgrail
Created April 17, 2012 21:45
Show Gist options
  • Save rob-mcgrail/2409280 to your computer and use it in GitHub Desktop.
Save rob-mcgrail/2409280 to your computer and use it in GitHub Desktop.
Getting hash of cookies for TKI SSO
class SSOAuth
require 'rubygems'
require 'mechanize'
def self.get_cookies(url)
h = {}
agent = Mechanize.new
agent.get(url) do |page|
if page.forms.first
agent.submit(page.forms.first)
agent.cookies.each do |c|
h[c.name] = c.value
end
end
end
h
end
end
h = SSOAuth.get_cookies('http://pasifika.tki.org.nz')
h.each do |k,v|
puts k
puts v
end
# Feeding to Anemone
opts = {
:discard_page_bodies => true,
:delay => $options.page_delay,
:redirect_limit => 1,
:accept_cookies => true,
:cookies => SSOAuth.get_cookies(@site.location),
}
Anemone.crawl(@site.location, opts) do |anemone|
anemone.on_every_page do |page|
puts page
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment