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