line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Ecrawler; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24210
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
264745
|
|
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
61
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
4
|
use Encode qw(decode encode decode_utf8 encode_utf8); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
64
|
|
6
|
1
|
|
|
1
|
|
4
|
use Mojo::IOLoop; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
19
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
383
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT = qw(geturlcontent getdiv); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Mojo::Ecrawler - A Eeay crawler for html page! |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 0.02 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Mojo::Ecrawler; |
31
|
|
|
|
|
|
|
$lurl='http://www.oschina.net'; |
32
|
|
|
|
|
|
|
$re1="div.TodayNews";#scope tag |
33
|
|
|
|
|
|
|
$re2="li a";# line tag |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $pcontent=geturlcontent($lurl); |
36
|
|
|
|
|
|
|
my $pcout=getdiv($pcontent,$re1,$re2); |
37
|
|
|
|
|
|
|
print $pcout; |
38
|
|
|
|
|
|
|
... |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 EXPORT |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 getulcontent() |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Using Mojo::UserAgent to get the page content。 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
IN: $url,the page's url. |
47
|
|
|
|
|
|
|
OUT:Mojo dom object . |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 getdiv() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Get content of filter using Mojo:DOM |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
IN:1,Mojo dom object; |
54
|
|
|
|
|
|
|
2,$re1: scope tag(div.xxx div#xxx div xx ..). |
55
|
|
|
|
|
|
|
3,$rel: line tag(a hi ..); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
OUT: the final content. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $DEBUG=0; |
62
|
|
|
|
|
|
|
sub geturlcontent { |
63
|
0
|
|
|
0
|
0
|
|
my $feed = shift; |
64
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
65
|
0
|
|
|
|
|
|
$ua->transactor->name( 'Mozilla/5.0 (Macintosh; ' |
66
|
|
|
|
|
|
|
. 'Intel Mac OS X 10_8_5) AppleWebKit/537.36 ' |
67
|
|
|
|
|
|
|
. '(KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36' ); |
68
|
0
|
|
|
|
|
|
my $recontent; |
69
|
0
|
|
|
|
|
|
my $result=($ua->get($feed)); |
70
|
0
|
|
|
|
|
|
return $result->res->dom; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub getdiv { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
|
my ($dom,$re1,$re2)=@_; |
76
|
0
|
|
|
|
|
|
my $recontent; |
77
|
0
|
|
|
|
|
|
my @div = $dom->find($re1)->each; |
78
|
0
|
|
|
|
|
|
$recontent.=getndiv($_,$re2) for(@div); |
79
|
0
|
0
|
|
|
|
|
print "DEBUG:getndiv()\::OUT:\n",$recontent if $DEBUG;; |
80
|
0
|
|
|
|
|
|
return $recontent; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub getndiv { |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#my $DEBUG=1; |
86
|
0
|
|
|
0
|
0
|
|
my ($st,$re)=@_; |
87
|
0
|
|
|
|
|
|
my $ndom=gmyc($st); |
88
|
0
|
|
|
|
|
|
my @ndiv = $ndom->find($re)->each; |
89
|
0
|
|
|
|
|
|
my $nrecontent; |
90
|
0
|
|
|
|
|
|
for(@ndiv){ |
91
|
0
|
|
|
|
|
|
$nrecontent.=$_->content; |
92
|
0
|
|
|
|
|
|
$nrecontent.=" ".$_->attr->{href}; |
93
|
0
|
|
|
|
|
|
$nrecontent.="\n"; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
0
|
|
|
|
|
print "DEBUG:getndiv()\::OUT:\n",$nrecontent if $DEBUG; |
96
|
0
|
|
|
|
|
|
return $nrecontent; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub gmyc { |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
0
|
|
my ($c,$s)=@_; |
103
|
0
|
0
|
|
|
|
|
my $dom =$s ? Mojo::DOM->new($c)->at($s): Mojo::DOM->new($c); |
104
|
|
|
|
|
|
|
# say Dump($dom); |
105
|
0
|
|
|
|
|
|
return $dom; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
ORANGE, C<< >> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 BUGS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
117
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
118
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SUPPORT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
perldoc Mojo::Ecrawler |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
You can also look for information at: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * CPAN Ratings |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * Search CPAN |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright 2016 ORANGE. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This program is released under the following license: Perl |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; # End of Mojo::Ecrawler |