line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NewsExtractor::SiteSpecificExtractor::news_cts_com_tw; |
2
|
1
|
|
|
1
|
|
8
|
use utf8; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
35
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
extends 'NewsExtractor::SiteSpecificExtractor'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
331
|
use Importer 'NewsExtractor::TextUtil' => qw< html2text normalize_whitespace >; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub headline { |
9
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
10
|
0
|
0
|
|
|
|
|
if (my $el = $self->dom->at('h1[itemprop="headline"]')) { |
11
|
0
|
|
|
|
|
|
return $el->all_text; |
12
|
|
|
|
|
|
|
} |
13
|
0
|
|
|
|
|
|
return undef; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub content_text { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
0
|
0
|
|
|
|
|
if (my $el = $self->dom->at('div[itemprop="articleBody"]')) { |
19
|
0
|
|
|
|
|
|
return html2text( $el->to_string ); |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
|
return undef; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub dateline { |
25
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
26
|
0
|
0
|
|
|
|
|
if (my $el = $self->dom->at('p[itemprop="datePublished"]')) { |
27
|
0
|
|
|
|
|
|
return $el->attr("datetime"); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
return undef; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub journalist { |
33
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if (my $el = $self->dom->at("div.artical-content")) { |
37
|
0
|
|
|
|
|
|
my $p_first = $el->at("p"); |
38
|
0
|
|
|
|
|
|
my $line = $p_first->all_text; |
39
|
0
|
0
|
|
|
|
|
if ($line =~ m{([\p{Letter}\p{Space}])報導\s*/\s*\p{Letter}{1,5}}) { |
40
|
0
|
|
|
|
|
|
return normalize_whitespace($line); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @patterns = ( |
45
|
|
|
|
|
|
|
qr{^(.+?\s*報導\s*/\s*\S+)\s?\n}, |
46
|
|
|
|
|
|
|
qr<\A (\p{Letter}+? \s+ 採訪/撰稿 \s+ \p{Letter}+? \s+ 攝影/剪輯) \s+ />x, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $content_text = $self->content_text; |
50
|
0
|
|
|
|
|
|
my @matched; |
51
|
0
|
|
|
|
|
|
for my $pat (@patterns) { |
52
|
0
|
|
|
|
|
|
@matched = $content_text =~ m/$pat/; |
53
|
0
|
0
|
|
|
|
|
last if @matched; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $matched[0]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |