« NewsExtractor/SiteSpecificExtractor/newnet_tw.pm
↑ Summary
NewsExtractor/Role/ContentTextExtractor.pm »
| 1 | package NewsExtractor::SiteSpecificExtractor::news_cts_com_tw; | ||||||||||
| 2 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | extends 'NewsExtractor::SiteSpecificExtractor'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Importer 'NewsExtractor::TextUtil' => qw< html2text normalize_whitespace >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | sub headline { | ||||||||
|
Subroutine
headline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 9 | 0 | my ($self) = @_; | |||||||||
| 10 | 0 | ▶ | if (my $el = $self->dom->at('h1[itemprop="headline"]')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 0 | return $el->all_text; | |||||||||
| 12 | } | ||||||||||
| 13 | 0 | return undef; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub content_text { | ||||||||
|
Subroutine
content_text: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 17 | 0 | my ($self) = @_; | |||||||||
| 18 | 0 | ▶ | if (my $el = $self->dom->at('div[itemprop="articleBody"]')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | return html2text( $el->to_string ); | |||||||||
| 20 | } | ||||||||||
| 21 | 0 | return undef; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub dateline { | ||||||||
|
Subroutine
dateline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 25 | 0 | my ($self) = @_; | |||||||||
| 26 | 0 | ▶ | if (my $el = $self->dom->at('p[itemprop="datePublished"]')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | return $el->attr("datetime"); | |||||||||
| 28 | } | ||||||||||
| 29 | 0 | return undef; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub journalist { | ||||||||
|
Subroutine
journalist: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 33 | 0 | my ($self) = @_; | |||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | if (my $el = $self->dom->at("div.artical-content")) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | my $p_first = $el->at("p"); | |||||||||
| 38 | 0 | my $line = $p_first->all_text; | |||||||||
| 39 | 0 | ▶ | if ($line =~ m{([\p{Letter}\p{Space}])報導\s*/\s*\p{Letter}{1,5}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | last if @matched; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | return $matched[0]; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1 | 1; | |||||||||