line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::YahooJapan::Baseball::Parser; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
32778
|
use utf8; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1537
|
use Web::Scraper; |
|
2
|
|
|
|
|
198972
|
|
|
2
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub parse_games_page { |
8
|
0
|
|
|
0
|
0
|
0
|
my $date = shift; |
9
|
0
|
|
|
|
|
0
|
my $league = shift; |
10
|
0
|
|
|
|
|
0
|
my %params = @_; |
11
|
|
|
|
|
|
|
my $day_scraper = scraper { |
12
|
0
|
|
|
0
|
|
0
|
process_first '//*[@id="gm_sch"]/div[contains(@class, "' . $league . '")]', 'league_name' => 'TEXT'; |
13
|
0
|
|
|
|
|
0
|
process '//*[@id="gm_sch"]/div[contains(@class, "' . $league . '")]/following-sibling::div[position() <= 2 and contains(@class, "NpbScoreBg")]//a[starts-with(@href, "/npb/game/' . $date . '") and not(contains(@href, "/top"))]', 'uris[]' => '@href'; |
14
|
0
|
|
|
|
|
0
|
}; |
15
|
0
|
0
|
|
|
|
0
|
my $res = $day_scraper->scrape(defined $params{html} ? ($params{html}, $params{uri}) : $params{uri}); |
16
|
0
|
|
|
|
|
0
|
my %league_names = ( |
17
|
|
|
|
|
|
|
NpbPl => 'パ・リーグ', |
18
|
|
|
|
|
|
|
NpbCl => 'セ・リーグ', |
19
|
|
|
|
|
|
|
NpbIl => '交流戦' |
20
|
|
|
|
|
|
|
); |
21
|
0
|
0
|
|
|
|
0
|
if ($res->{league_name} eq $league_names{$league}) { |
22
|
0
|
|
|
|
|
0
|
return @{$res->{uris}}; |
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
0
|
|
|
|
|
0
|
return (); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub parse_game_player_row { |
30
|
31
|
|
|
31
|
0
|
41
|
my $cells = shift; |
31
|
31
|
|
|
|
|
42
|
my $stats = {}; |
32
|
|
|
|
|
|
|
|
33
|
31
|
|
|
|
|
207
|
my %position_table = ( |
34
|
|
|
|
|
|
|
'投' => 'p', |
35
|
|
|
|
|
|
|
'捕' => 'c', |
36
|
|
|
|
|
|
|
'一' => '1b', |
37
|
|
|
|
|
|
|
'二' => '2b', |
38
|
|
|
|
|
|
|
'三' => '3b', |
39
|
|
|
|
|
|
|
'遊' => 'ss', |
40
|
|
|
|
|
|
|
'左' => 'lf', |
41
|
|
|
|
|
|
|
'中' => 'cf', |
42
|
|
|
|
|
|
|
'右' => 'rf', |
43
|
|
|
|
|
|
|
'指' => 'dh', |
44
|
|
|
|
|
|
|
'打' => 'ph', |
45
|
|
|
|
|
|
|
'走' => 'pr' |
46
|
|
|
|
|
|
|
); |
47
|
31
|
|
|
|
|
62
|
my @positions = (); |
48
|
31
|
|
|
|
|
57
|
my $pos_rep = shift @$cells; |
49
|
31
|
100
|
|
|
|
109
|
if ($pos_rep =~ /^\((.*)\)$/) { |
50
|
20
|
|
|
|
|
30
|
my $i = 0; |
51
|
20
|
|
|
|
|
69
|
for my $p (split //, $1) { |
52
|
|
|
|
|
|
|
push(@positions, { |
53
|
72
|
100
|
|
|
|
260
|
position => $position_table{$p}, |
54
|
|
|
|
|
|
|
is_starting => $i++ > 0 ? 0 : 1 |
55
|
|
|
|
|
|
|
}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
11
|
|
|
|
|
28
|
for my $p (split //, $pos_rep) { |
60
|
|
|
|
|
|
|
push(@positions, { |
61
|
33
|
|
|
|
|
90
|
position => $position_table{$p}, |
62
|
|
|
|
|
|
|
is_starting => 0 |
63
|
|
|
|
|
|
|
}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
31
|
|
|
|
|
80
|
$stats->{positions} = \@positions; |
67
|
|
|
|
|
|
|
|
68
|
31
|
|
|
|
|
49
|
my $player_name = shift @$cells; |
69
|
|
|
|
|
|
|
|
70
|
31
|
|
|
|
|
90
|
my @indexes = qw(avg ab r h rbi k bbhbp shsf sb e hr); |
71
|
31
|
|
|
|
|
46
|
for my $i (@indexes) { |
72
|
341
|
|
|
|
|
712
|
$stats->{$i} = shift @$cells; |
73
|
|
|
|
|
|
|
} |
74
|
31
|
|
|
|
|
42
|
my $bi = 1; |
75
|
31
|
|
|
|
|
52
|
$stats->{innings} = {}; |
76
|
31
|
|
|
|
|
50
|
for my $bat (@$cells) { |
77
|
279
|
100
|
|
|
|
822
|
$stats->{innings}->{$bi++} = $bat ne '' ? [$bat] : []; |
78
|
|
|
|
|
|
|
} |
79
|
31
|
|
|
|
|
160
|
return $player_name, $stats; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub parse_game_stats_page { |
83
|
1
|
|
|
1
|
0
|
5020
|
my %params = @_; |
84
|
|
|
|
|
|
|
my $stats_scraper = scraper { |
85
|
|
|
|
|
|
|
process '//*[@id="st_batth" or @id="st_battv"]//tr', 'lines[]' => scraper { |
86
|
35
|
|
|
|
|
1081665
|
process '//td', 'cells[]' => 'TEXT'; |
87
|
35
|
|
|
|
|
160708
|
process_first '//a[contains(@href, "/npb/player")]', 'player_uri' => '@href'; |
88
|
1
|
|
|
1
|
|
591167
|
}; |
89
|
1
|
|
|
|
|
40
|
}; |
90
|
1
|
50
|
|
|
|
44
|
my $res = $stats_scraper->scrape(defined $params{html} ? ($params{html}, $params{uri}) : $params{uri}); |
91
|
1
|
|
|
|
|
21117
|
my @players = (); |
92
|
1
|
|
|
|
|
2
|
for my $line (@{$res->{lines}}) { |
|
1
|
|
|
|
|
5
|
|
93
|
35
|
|
|
|
|
61
|
my $cells = $line->{cells}; |
94
|
35
|
100
|
66
|
|
|
249
|
unless ($cells and $line->{player_uri}) { |
95
|
4
|
|
|
|
|
8
|
next; |
96
|
|
|
|
|
|
|
} |
97
|
31
|
|
|
|
|
234
|
my ($player_name, $player_stats) = WWW::YahooJapan::Baseball::Parser::parse_game_player_row($cells); |
98
|
|
|
|
|
|
|
$player_stats->{player} = { |
99
|
|
|
|
|
|
|
name => $player_name, |
100
|
|
|
|
|
|
|
uri => $line->{player_uri}, |
101
|
|
|
|
|
|
|
$line->{player_uri}->query_form |
102
|
31
|
|
|
|
|
112
|
}; |
103
|
31
|
|
|
|
|
1092
|
push(@players, $player_stats); |
104
|
|
|
|
|
|
|
} |
105
|
1
|
|
|
|
|
52
|
@players; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |