line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
46968
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
160
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Finance::Bank::SCSB::TW; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
268
|
|
6
|
3
|
|
|
3
|
|
71
|
use 5.008; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
184
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
8
|
3
|
|
|
3
|
|
5686
|
use WWW::Mechanize; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use HTML::Selector::XPath qw(selector_to_xpath); |
10
|
|
|
|
|
|
|
use HTML::TreeBuilder::XPath; |
11
|
|
|
|
|
|
|
use utf8; |
12
|
|
|
|
|
|
|
use List::MoreUtils qw(mesh); |
13
|
|
|
|
|
|
|
use Finance::Bank::SCSB::TW::CurrencyExchangeRateCollection; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my $ua; |
17
|
|
|
|
|
|
|
sub ua { |
18
|
|
|
|
|
|
|
return $ua if $ua; |
19
|
|
|
|
|
|
|
$ua = WWW::Mechanize->new( |
20
|
|
|
|
|
|
|
env_proxy => 1, |
21
|
|
|
|
|
|
|
keep_alive => 1, |
22
|
|
|
|
|
|
|
timeout => 60, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
$ua->agent_alias("Windows IE 6"); |
25
|
|
|
|
|
|
|
return $ua; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _login { |
30
|
|
|
|
|
|
|
my ($id, $username, $password, $menu) = @_; |
31
|
|
|
|
|
|
|
$menu ||= "menu1"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
ua->get('https://ibank.scsb.com.tw/'); |
34
|
|
|
|
|
|
|
ua->get('https://ibank.scsb.com.tw/mainbody.jsp'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
ua->submit_form( |
37
|
|
|
|
|
|
|
form_name => 'loginForm', |
38
|
|
|
|
|
|
|
fields => { |
39
|
|
|
|
|
|
|
userID => $id, |
40
|
|
|
|
|
|
|
loginUID => $username |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
ua->submit_form( |
45
|
|
|
|
|
|
|
form_name => 'loginForm', |
46
|
|
|
|
|
|
|
fields => { |
47
|
|
|
|
|
|
|
password => $password, |
48
|
|
|
|
|
|
|
'wlw-radio_button_group_key:{actionForm.loginAP}' => $menu |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return ua->content; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub logout { |
56
|
|
|
|
|
|
|
ua->get("https://ibank.scsb.com.tw/logout.do"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub css { |
60
|
|
|
|
|
|
|
selector_to_xpath(shift) |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _cssQuery { |
64
|
|
|
|
|
|
|
my ($content, $selector) = @_; |
65
|
|
|
|
|
|
|
my $tree = HTML::TreeBuilder::XPath->new; |
66
|
|
|
|
|
|
|
$tree->parse($content); |
67
|
|
|
|
|
|
|
$tree->findnodes( selector_to_xpath($selector) ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub check_balance { |
71
|
|
|
|
|
|
|
my ($id, $username, $password) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
die "Invalid parameters." unless $id && $username && $password; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $content = _login($id, $username, $password, "menu3"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $nodes = _cssQuery($content, ".txt07 div[align='center'], .txt10 div[align='center'] span"); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my %balance = ( map { $_->as_trimmed_text } @$nodes ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
for (keys %balance) { |
82
|
|
|
|
|
|
|
$balance{$_} =~ s/,//; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
logout; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $balance{"存款"} if defined($balance{"存款"}); |
88
|
|
|
|
|
|
|
return -1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub currency_exchange_rate { |
92
|
|
|
|
|
|
|
my $url = 'https://ibank.scsb.com.tw/netbank.portal?_nfpb=true&_pageLabel=page_other12&_nfls=false'; |
93
|
|
|
|
|
|
|
ua->get($url); |
94
|
|
|
|
|
|
|
my $content = ua->content; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $tree = HTML::TreeBuilder::XPath->new; |
97
|
|
|
|
|
|
|
$tree->parse($content); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my @xp = map { |
100
|
|
|
|
|
|
|
[ map { $_->as_trimmed_text } $tree->findnodes($_) ] |
101
|
|
|
|
|
|
|
} ( |
102
|
|
|
|
|
|
|
selector_to_xpath("td.txt09 > span"), |
103
|
|
|
|
|
|
|
selector_to_xpath("td.txt09 + td > span"), |
104
|
|
|
|
|
|
|
selector_to_xpath("td.txt09 + td + td.txt101 > span"), |
105
|
|
|
|
|
|
|
selector_to_xpath("td.txt09 + td + td.txt101 + td.txt101 > span") |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $table = []; |
109
|
|
|
|
|
|
|
my @field_names = qw(zh_currency_name en_currency_name buy_at sell_at); |
110
|
|
|
|
|
|
|
for my $row (0..scalar(@{$xp[0]})-1) { |
111
|
|
|
|
|
|
|
my @row = (); |
112
|
|
|
|
|
|
|
for my $node_text (@xp) { |
113
|
|
|
|
|
|
|
my $str = $node_text->[$row]; |
114
|
|
|
|
|
|
|
push @row, $str; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
$row[0] =~ s/\p{IsSpace}+//g; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
push @$table, { mesh @field_names, @row }; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return bless $table, "Finance::Bank::SCSB::TW::CurrencyExchangeRateCollection"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |