Skip to content

Instantly share code, notes, and snippets.

@ymrl
Created September 12, 2012 06:42
Show Gist options
  • Save ymrl/3704741 to your computer and use it in GitHub Desktop.
Save ymrl/3704741 to your computer and use it in GitHub Desktop.
日吉キャンパスのネットワーク用のアレ
require 'mechanize'
require 'pit'
config = Pit.get("keiojp",:require => {
"account" => "Your keio.jp account",
"password" => "Your keio.jp password"
})
@agent = Mechanize.new
@agent.max_history = 5
@agent.get 'https://authserv2.hc.keio.ac.jp/login.html'
@form = @agent.page.forms[0]
@form.field('name').value = config["account"]
@form.field('pass').value = config["password"]
def authorize
begin
@form.submit
rescue
sleep 60
retry
end
end
authorize
refresh_uri = @agent.page.meta_refresh.first.uri
loop do
begin
puts "getting #{refresh_uri}"
@agent.get refresh_uri
rescue
sleep 60
authorize
retry
end
sleep 60
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment