Skip to content

Instantly share code, notes, and snippets.

@koduki
Created October 2, 2010 07:30
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 koduki/607418 to your computer and use it in GitHub Desktop.
Save koduki/607418 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
id = ''
password = ''
denpyoNo = ''
date = '20101003'
time = '20100' # 20000, 20100, 20200, 20300, 20400, 20500, 20600
require 'mechanize'
def go page, &callback
callback.call page.forms.first
end
agent = WWW::Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
# step0
page = agent.get('https://cmypage.kuronekoyamato.co.jp/portal/entrance?id=kojintop')
# step1
page = go page do |f|
f.fields_with(:name => 'id').first.value = id
f.fields_with(:name => 'passwd').first.value = password
f.click_button
end
# step2
page = page.links.select{|link|link.text == '■再配達を依頼したい'}.first.click
# step3
page = go page do |f|
f.field_with('denpyoNo').value = denpyoNo
f.click_button
end
# step4
page = page.forms.first.click_button
# step5
page = go page do |f|
f.field_with(:name => 'saihaiKiboubi').value = date
f.field_with(:name => 'saihaiKiboujikantai').value = time
f.click_button(f.button_with(:name => 'BTN_NEXT'))
end
# step6
page = page.forms.first.click_button
# isSuccess
title = page.title.bytes.to_a[4..-1].pack('C*').force_encoding 'utf-8'
if title =~ /配達受付完了/
true
else
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment