Skip to content

Instantly share code, notes, and snippets.

@you21979
Last active August 29, 2015 14:07
Show Gist options
  • Save you21979/12f6fb530fce05a4a73c to your computer and use it in GitHub Desktop.
Save you21979/12f6fb530fce05a4a73c to your computer and use it in GitHub Desktop.
crawler-test
var vpass = require('./vpass');
var auth = {
userid:process.env['ID'],
password:process.env['PASS'],
strURL:'https%3A%2F%2Fwww%2Esmbc-card%2Ecom%2Fmem%2Fvps%2Findex%2Ejsp',
};
var v = new vpass();
v.doLogin(auth).
then(v.thenDownload()).
then(v.thenPoint()).
then(function(){console.log(v.data)})
var CookieSession = require('crawler.io').CookieSession;
var Iconv = require('iconv').Iconv;
var c = new CookieSession();
var auth = {
userid:process.env['ID'],
password:process.env['PASS'],
strURL:'https%3A%2F%2Fwww%2Esmbc-card%2Ecom%2Fmem%2Fvps%2Findex%2Ejsp',
};
c.postLogin('https://www.smbc-card.com/vp/xt_login.do', auth).then(function(res){
if( res.match(/が正しくありません。/) ){
throw new Error('login error');
}
return res;
}).then(function(){
return c.get('https://www.smbc-card.com/vp/web_meisai/web_meisai_top.do').then(function(res){
var link = res.match(/<a href="(.*)\">CSV(.*)<\/a>/).shift();
var url = link.match(/<a href="(.*)\">/)[1];
return c.getBinary('https://www.smbc-card.com' + url)
}).then(function(binary){
var iconv = new Iconv('SHIFT_JIS', 'utf-8');
return iconv.convert(binary).toString('utf-8');
})
}).then(function(data){
console.log(data);
})
var CookieSession = require('crawler.io').CookieSession;
var Iconv = require('iconv').Iconv;
var vpass = function(){
this.session = new CookieSession();
this.data = {};
}
vpass.prototype.doLogin = function(auth){
return this.session.postLogin('https://www.smbc-card.com/vp/xt_login.do', auth).then(function(res){
if( res.match(/が正しくありません。/) ){
throw new Error('login error');
}
return res;
})
}
vpass.prototype.thenDownload = function(){
var self = this;
return function(){
return self.session.get('https://www.smbc-card.com/vp/web_meisai/web_meisai_top.do').then(function(res){
var link = res.match(/<a href="(.*)\">CSV(.*)<\/a>/).shift();
var url = link.match(/<a href="(.*)\">/)[1];
return self.session.getBinary('https://www.smbc-card.com' + url)
}).then(function(binary){
var iconv = new Iconv('SHIFT_JIS', 'utf-8');
return iconv.convert(binary).toString('utf-8');
}).then(function(data){
self.data['meisai'] = data;
return data;
})
}
}
vpass.prototype.thenPoint = function(){
var self = this;
return function(){
return self.session.get('https://www.smbc-card.com/vp/wpc/xt_wpc_shokai.do').then(function(res){
var p = res.match(/<SPAN CLASS=\"sc89\">(.*)<BR><\/SPAN>/).shift();
var point = p.match(/<SPAN CLASS=\"sc89\">(.*)<BR>/)[1].split(' ').shift();
return parseInt(point.replace(',',''));
}).then(function(data){
self.data['point'] = data;
return data;
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment