Skip to content

Instantly share code, notes, and snippets.

@MasWag
Last active December 29, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasWag/7699888 to your computer and use it in GitHub Desktop.
Save MasWag/7699888 to your computer and use it in GitHub Desktop.
utroamにloginするscript
#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
require 'kconv'
require "pit"
username , password = ARGV
if (config = Pit.get("utroam-password")) == {} then
if ARGV.length < 2 then
print "username >"
username = $stdin.gets.chop
print "password >"
system "stty -echo"
password = $stdin.gets.chop
system "stty echo"
end
Pit.set("utroam-password",:data => {"username"=>username, "pass" =>password})
p ""
elsif ARGV.length < 2
username , password = config["username"] , config["pass"]
end
agent = Mechanize.new
login_page = agent.get(URI.parse('https://wl-sw2.nc.u-tokyo.ac.jp/upload/custom/defender/login.htm'))
login_page.forms[0].field_with(:name => 'user').value = username
login_page.forms[0].field_with(:name => 'password').value = password
login_page.forms[0].click_button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment