Created
November 8, 2014 20:13
-
-
Save takuya/10eea4a41aa1d7afe807 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# coding : utf-8 | |
require 'mechanize' | |
require 'pp' | |
require 'logger' | |
require 'cgi' | |
class NcorsSystem | |
attr_accessor :m , :login_url,:home_url,:user_info,:my_yoyaku | |
def initialize(id,pw) | |
@@id = id | |
@@pw = pw | |
@m = Mechanize.new | |
@user_info ={} | |
@my_yoyaku | |
m.user_agent_alias = 'Mac Safari' | |
#m.log = Logger.new $stderr | |
end | |
def login () | |
m.get login_url | |
retry_cnt = 0 | |
begin | |
m.page.forms[0].fields[0].value = @@id | |
m.page.forms[0].fields[1].value = @@pw | |
m.page.form.submit | |
raise if m.page.uri.to_s =~ /login/ | |
rescue => e | |
q = m.page.uri.query | |
params = nil; | |
if q != nil then | |
params = CGI.parse(q) | |
params.each{|k,v| params[k.toutf8]=v.map{|e|e.toutf8} } | |
puts params | |
end | |
retry_cnt = retry_cnt+1 | |
retry if retry_cnt < 3 | |
msg = "ログインに失敗" | |
msg = msg ":" + params.inspect if q | |
msg = msg + m.page.uri.to_s | |
raise msg | |
end | |
end | |
def go_yoyaku_and_get_yoyaku_table | |
m.page.form_with(:name => /TypeSelect/).submit | |
m.page.search("*[onclick]").remove | |
my_yoyaku = m.page.search(".Reservation").first.to_html.toutf8 | |
m.page.form_with(:name=> /BackTo/).submit # go_home | |
my_yoyaku | |
end | |
def send_yoyaku_mail | |
m.page.form_with(:name=> /mailsend/).submit | |
m.page.form.submit # go_to_home | |
end | |
def go_home | |
self.login | |
[1,2,3].each{|e| | |
key = m.page.search("//table[@class='UserInfo'][1]//tr//th[#{e}]").text.tosjis.toutf8.strip | |
val = m.page.search("//table[@class='UserInfo'][1]//tr//td[#{e}]").text.tosjis.toutf8.strip.gsub(/\s/,"") | |
user_info[key] = val | |
} | |
[1,2,3,4,5].each{|e| | |
key = m.page.search("//table[@class='UserInfo'][2]//tr//th[#{e}]").text.tosjis.toutf8.strip | |
val = m.page.search("//table[@class='UserInfo'][2]//tr//td[#{e}]").text.tosjis.toutf8.strip.gsub(/\s/,"") | |
user_info[key] = val | |
} | |
end | |
end | |
class OrixDrivingSchool < NcorsSystem | |
def initialize(id,pw) | |
super | |
@login_url = "https://dk.ncors.com/orix/ncors/login.asp" | |
@home_url = "https://dk.ncors.com/orix/ncors/cartype.asp" | |
end | |
end | |
def main() | |
id = "your_login_id" | |
pw = "your_login_password" | |
orix = OrixDrivingSchool.new( id, pw ) | |
orix.login | |
orix.send_yoyaku_mail | |
#orix.go_home | |
#info = orix.user_info | |
#html = orix.go_yoyaku_and_get_yoyaku_table | |
end | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment