lib/Novel/Robot/Parser/jjwxc.pm

filter: Statementstmt 40.5% 45 / 111 Branchbran 6.2% 1 / 16 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 36.0% 9 / 25 Podpod 0.0% 0 / 12 totaltotal 31.4% 56 / 178 CC 16 SCAR 17.3
CC
16
Cov
35%
__ANON__
12.0
parse_writer_series_name
12.0
parse_writer_book_info
12.0
CRAP 5.7
« lib/Novel/Robot/Parser/txt.pm ↑ Summary lib/Novel/Robot/Parser/tieba.pm »
1 # ABSTRACT: https://www.jjwxc.net
2  
3 =pod
4  
5 =encoding utf8
6  
7 =head1 FUNCTION
8  
9 =cut
10  
11 package Novel::Robot::Parser::jjwxc;
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base 'Novel::Robot::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Web::Scraper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 #use Data::Dumper;
20 #use Smart::Comments;
21  
22 0 ▶sub base_url { 'https://www.jjwxc.net' }
Subroutine base_url: not called CC=1 SCAR=6.9
Pod undocumented
23  
24 0 ▶sub domain { 'jjwxc.net' }
Subroutine domain: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 sub generate_novel_url {
27 1 ▶ my ( $self, $index_url ) = @_;
Subroutine generate_novel_url: called CC=2 SCAR=7.0
Pod undocumented
28 1 my ( $novelid ) = $index_url =~ m#novelid=(\d+)#;
29 1 ▶ my $u = $novelid ? "https://m.jjwxc.net/book2/$novelid?more=0&whole=1" : $index_url;
Branch: 1 branch
BranchTrueFalseTotal
$novelid ? : 1 0 1
30 1 return $u;
31 }
32  
33 sub parse_novel {
34 1 ▶ my ( $self, $h , $r) = @_;
Subroutine parse_novel: called CC=2 SCAR=6.9
Pod undocumented
35 1 $$h =~ s#本书霸王票读者排行.*##s;
36  
37 1 my ($title)= $$h=~m#<title>(.+?)<\/title>#s;
38 1 ( $r->{book}, $r->{writer} ) = $title =~ m#\s*《(.+?)》(.+?)_晋江文学城#s;
39  
40 1 my ( $cc ) = $$h =~ m#章节列表:<br/>.+?(<a.+?)<\/div>#s;
41 1 my @f = $cc =~ m#<a.+?href="(.+?/\d+/\d+.*?)".+?>(.+?)</a>#sg;
42 1 my $max_chapter_num = ( $#f + 1 ) / 2;
43 1 for my $i ( 1 .. $max_chapter_num ) {
44 10 my $j = 2 * $i - 1;
45 10 my $t = $f[$j];
46 10 $t =~ s/^\d+\.(&nbsp;)*//;
47 10 $t =~ s/&nbsp/ /g;
48 10 $t =~ s/^.+>//;
49 10 $t =~ s/\s+/ /g;
50  
51 10 my $ui = 2 * $i - 2;
52 10 my $u = "https://m.jjwxc.net$f[$ui]";
53 10 push @{ $r->{item_list} }, { id => $i, title => $t, url => $u };
54 }
55  
56 1 return $r;
57 } ## end sub parse_novel
58  
59 sub parse_novel_item {
60 1 ▶ my ( $self, $h ) = @_;
Subroutine parse_novel_item: called CC=2 SCAR=7.1
Pod undocumented
61  
62 1 my ( $c ) = $$h =~ m#<h2[^>]+>.+?<li[^>]*>(.+?)</li>#s;
63  
64 1 ▶ return { content => $c || '' };
Condition50%1/2
$c || ''
l!l
10
MC/DC0%0/1
$c || ''
$c
Truth table50%1/2
A
A= $c
Aresult
11
00
65 }
66  
67 sub parse_board {
68 0 ▶ my ( $self, $h ) = @_;
Subroutine parse_board: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 my $parse_writer = scraper {
71 0 ▶ process_first '//tr[@valign="bottom"]//b', writer => 'TEXT';
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 };
73 0 my $ref = $parse_writer->scrape( $h );
74  
75 0 $self->tidy_string( $ref, 'writer' );
76 0 return { writer => $ref->{writer} };
77 }
78  
79 sub parse_board_item {
80 0 ▶ my ( $self, $h ) = @_;
Subroutine parse_board_item: not called CC=2 SCAR=17.9
Pod undocumented
81 0 my @book_list;
82 0 my $series = '未分类';
83  
84 my $parse_writer = scraper {
85 process '//tr[@bgcolor="#eefaee"]', 'book_list[]' => sub {
86 0 ▶ my $tr = $_[0];
Subroutine __ANON__: not called CC=3 SCAR=24.8
87 0 $series = $self->parse_writer_series_name( $tr, $series );
88  
89 0 my $book = $self->parse_writer_book_info( $tr, $series );
90 0 ▶ push @book_list, $book if ( $book and $book->{url} =~ /onebook/ );
Branch: 1 branch
BranchTrueFalseTotal
if $book and $book->{"url"} =~ /onebook/ 0 0 0
Condition0%0/3
$book and $book->{"url"} =~ /onebook/
!ll&&!rl&&r
000
MC/DC0%0/2
$book and $book->{"url"} =~ /onebook/
$book $book->{"url"} =~ /onebook/
Truth table0%0/3
A and B
A= $bookB= $book->{"url"} =~ /onebook/
ABresult
0X0
100
111
91 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 };
93  
94 0 my $ref = $parse_writer->scrape( $h );
95  
96 0 $self->tidy_string( $ref, 'writer' );
97 0 $_->{writer} = $ref->{writer} for @book_list;
98  
99 0 return \@book_list;
100 } ## end sub parse_board_item
101  
102 sub parse_writer_series_name {
103 0 ▶ my ( $self, $tr, $series ) = @_;
Subroutine parse_writer_series_name: not called CC=3 SCAR=24.8
Pod undocumented
104  
105 0 ▶ return $series unless ( $tr->look_down( 'colspan', '7' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $tr->look_down("colspan", 7) 0 0 0
106  
107 0 ▶ if ( $tr->as_trimmed_text =~ /【(.*)】/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tr->as_trimmed_text =~ /\x{3010}(.*)\x{3011}/) 0 0 0
108 0 $series = $1;
109 }
110  
111 0 return $series;
112 }
113  
114 sub parse_writer_book_info {
115 0 ▶ my ( $self, $tr, $series ) = @_;
Subroutine parse_writer_book_info: not called CC=3 SCAR=24.8
Pod undocumented
116  
117 0 my $book = $tr->look_down( '_tag', 'a' );
118 0 ▶ return unless ( $book );
Branch: 1 branch
BranchTrueFalseTotal
unless $book 0 0 0
119  
120 0 my $book_url = $book->attr( 'href' );
121  
122 0 my $bookname = $book->as_trimmed_text;
123 0 substr( $bookname, 0, 1 ) = '';
124 0 ▶ $bookname .= '[锁]' if ( $tr->look_down( 'color', 'gray' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $tr->look_down("color", "gray") 0 0 0
125  
126 0 my $status = ( $tr->look_down( '_tag', 'td' ) )[4]->as_trimmed_text;
127 return {
128 0 series => $series,
129 book => "$bookname($status)",
130 url => $self->base_url() . "/$book_url",
131 };
132  
133 } ## end sub parse_writer_book_info
134  
135 sub make_query_request {
136  
137 0 ▶ my ( $self, $keyword, %opt ) = @_;
Subroutine make_query_request: not called CC=2 SCAR=17.9
Pod undocumented
138 0 ▶ $opt{query_type} ||= '作品';
Condition0%0/2
$opt{"query_type"} ||= "\x{4f5c}\x{54c1}"
l!l
00
MC/DC0%0/1
$opt{"query_type"} ||= "\x{4f5c}\x{54c1}"
$opt{"query_type"}
Truth table0%0/2
A
A= $opt{"query_type"}
Aresult
11
00
139  
140 0 my %qt = (
141 '作品' => '1',
142 '作者' => '2',
143 '主角' => '4',
144 '配角' => '5',
145 '其他' => '6',
146 );
147  
148 0 $keyword = $self->encode_cjk_for_url($keyword);
149 0 my $url = $self->base_url() . qq[/search.php?kw=$keyword&t=$qt{$opt{query_type}}];
150 #$url = encode( $self->charset(), $url );
151  
152 0 return $url;
153 } ## end sub make_query_request
154  
155 sub parse_query_list {
156 0 ▶ my ( $self, $h ) = @_;
Subroutine parse_query_list: not called CC=2 SCAR=17.9
Pod undocumented
157 my $parse_query = scraper {
158 process '//div[@class="page"]/a', 'urls[]' => sub {
159 0 ▶ return unless ( $_[0]->as_text =~ /^\[\d*\]$/ );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->as_text =~ /^\[\d*\]$/ 0 0 0
160 0 my $url = $self->base_url() . ( $_[0]->attr( 'href' ) );
161 0 $url = encode( $self->charset(), $url );
162 0 return $url;
163 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
164 0 };
165 0 my $r = $parse_query->scrape( $h );
166 0 ▶ return $r->{urls} || [];
Condition0%0/2
$r->{'urls'} || []
l!l
00
MC/DC0%0/1
$r->{'urls'} || []
$r->{'urls'}
Truth table0%0/2
A
A= $r->{'urls'}
Aresult
11
00
167 } ##
168  
169 sub parse_query_item {
170 0 ▶ my ( $self, $h ) = @_;
Subroutine parse_query_item: not called CC=3 SCAR=24.8
Pod undocumented
171  
172 my $parse_query = scraper {
173 0 ▶ process '//h3[@class="title"]/a',
Subroutine __ANON__: not called CC=1 SCAR=6.9
174 'books[]' => {
175 'book' => 'TEXT',
176 'url' => '@href',
177 };
178  
179 process '//div[@class="info"]', 'writers[]' => sub {
180 0 ▶ my ( $writer, $status ) = $_[0]->as_text =~ /作者:(.+?) \┃ 进度:(\S+)/s;
Subroutine __ANON__: not called CC=1 SCAR=6.9
181 0 return { writer => $writer, status => $status };
182 0 };
183 0 };
184 0 my $ref = $parse_query->scrape( $h );
185  
186 0 my @result;
187 0 foreach my $i ( 0 .. $#{ $ref->{books} } ) {
188 0 my $r = $ref->{books}[$i];
189 0 ▶ next unless ( $r->{url} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"url"} 0 0 0
190  
191 0 my $w = $ref->{writers}[$i];
192 0 $r->{title} .= "($w->{status})";
193 0 push @result, { %$w, %$r };
194 }
195  
196 0 return \@result;
197 } ## end sub parse_query_item
198  
199 1 1;
« lib/Novel/Robot/Parser/txt.pm ↑ Summary lib/Novel/Robot/Parser/tieba.pm »