Created
April 17, 2012 21:45
-
-
Save rob-mcgrail/2409280 to your computer and use it in GitHub Desktop.
Getting hash of cookies for TKI SSO
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
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