スクレイピングでログインまでは何とかできたっぽい。先日トライして上手くいっていなかった原因は、「submitボタンにnameとvalueがある場合、その値もサーバーに送付される」というのを知らず、スルーしていたためでした。submitなんて全部同じだと思ってたよ・・・orz.
ということで、ログインするだけのクライアントライブラリは以下。
begin require 'rubygems' rescue LoadError end require 'httpclient' require 'rexml/document' require 'date' require 'kconv' module ClickClient class Client # ホスト名 DEFAULT_HOST_NAME = "https://sec-sso.click-sec.com/mf" # #===コンストラクタ # def initialize( proxy=nil ) @client = HTTPClient.new( proxy, "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6") #@client.debug_dev=STDOUT @client.set_cookie_store("cookie.dat") @host_name = DEFAULT_HOST_NAME end # ログインする def fx_session( userid, password, &block ) @client.get("#{@host_name}/" ) result = @client.post_content("#{@host_name}/sso-redirect", { "j_username"=>userid, "j_password"=>password, "LoginForm"=>"ログイン".tosjis, "s"=>"02", "p"=>"80" }) puts result.toutf8 # TODO end #ホスト名 attr :host_name, true end end
呼び出しのサンプル。
require 'clickclient_scrap' # ↑のコード USER=<ユーザーID> PASS=<パスワード> c = ClickClient::Client.new c.fx_session( USER, PASS )
実行結果です。
<html>
<head>
<title></title>
<!-- 125.215.74.87:Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 -->
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="content-script-type" content="text/javascript">
<meta http-equiv="content-style-type" content="text/css">
<meta name="author" content="CLICK Securities, Inc.">
<link type="text/css" rel="stylesheet" href="/ygmo/html/ygmo/css/style.css">
<link rel="shortcut icon" href="/ygmo/html/ygmo/img/favicon.ico">
<script type="text/javascript" src="/ygmo/html/ygmo/js/fenix.js"></script>
<script type="text/javascript" src="/ygmo/html/ygmo/js/javascript.js"></script>
<script type="text/javascript">
window.document.onkeydown = KeyEvent;
function KeyEvent(e) {
if (document.all) {
if (event.srcElement.type == 'text') {
if (event.keyCode == 13) {
event.returnValue = false;
}
}
}
}
</script>
<script>
if (window.name == null || window.name == '') {
window.name = 'CLICK_FX_HOME_TRADE';
}
location.replace('https://fx.click-sec.com/ygmo/servlet/switchAgent;jsessionid=xxx?SID=web9&AKEY=Ot00111.Ot00102&SESN=xxxx&P001=218029769&P002=999&FAGD=2&PAGE_NAME=GOt00102&PAGE_TYPE=1&WIN_NAME=' + window.name);
</script>
<NOSCRIPT>
<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=https://fx.click-sec.com/ygmo/servlet/switchAgent;jsessionid=xxx?SID=web9&AKEY=Ot00111.Ot00102&SESN=xxx&P001=218029769&P002=999&FAGD=2&PAGE_NAME=GOt00102&PAGE_TYPE=1">
</NOSCRIPT>
</head>
<body></body>
</html>さて、なにやらめんどくさそうなページに辿り着きましたよ。