line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
1
|
|
|
1
|
|
612
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
31471
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
157361
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
2633
|
use LWP::Protocol::https; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use HTTP::Cookies; |
6
|
|
|
|
|
|
|
use HTTP::Request::Common; |
7
|
|
|
|
|
|
|
use HTML::LinkExtor; |
8
|
|
|
|
|
|
|
use URI::URL; |
9
|
|
|
|
|
|
|
use IO::Handle; |
10
|
|
|
|
|
|
|
use English; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
GnaData::Load::Agent is a subclass of the LWP::UserAgent which allows |
15
|
|
|
|
|
|
|
redirects for POST requests |
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package GnaData::Load::Agent; |
19
|
|
|
|
|
|
|
@GnaData::Load::Agent::ISA = qw(LWP::UserAgent); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub redirect_ok { |
23
|
|
|
|
|
|
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package GnaData::Load; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
my $proto = shift; |
31
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
32
|
|
|
|
|
|
|
my $self = {}; |
33
|
|
|
|
|
|
|
bless ($self, $class); |
34
|
|
|
|
|
|
|
$self->{'agent'} = GnaData::Load::Agent->new(); |
35
|
|
|
|
|
|
|
$self->{'sleep'} = 1; |
36
|
|
|
|
|
|
|
$self->{'cookie_jar'} = HTTP::Cookies->new(); |
37
|
|
|
|
|
|
|
$self->{'agent'}->cookie_jar($self->{'cookie_jar'}); |
38
|
|
|
|
|
|
|
$self->{'found'} = {}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->{'output_handle'} = IO::Handle->new(); |
41
|
|
|
|
|
|
|
$self->{'output_handle'}->fdopen(fileno(STDOUT), "w"); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub load { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $get = shift; |
49
|
|
|
|
|
|
|
my $post = shift; |
50
|
|
|
|
|
|
|
my ($returnval) = ""; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if (defined($post)) { |
53
|
|
|
|
|
|
|
my $req = HTTP::Request::Common::POST($get, $post); |
54
|
|
|
|
|
|
|
my $res = $self->{'agent'}->request($req); |
55
|
|
|
|
|
|
|
$self->{'reply'} = $res->as_string; |
56
|
|
|
|
|
|
|
$self->{'base'} = $res->base; |
57
|
|
|
|
|
|
|
sleep($self->{'sleep'}); |
58
|
|
|
|
|
|
|
} elsif (defined($get)) { |
59
|
|
|
|
|
|
|
my $req = new HTTP::Request 'GET', $get; |
60
|
|
|
|
|
|
|
my $res = $self->{'agent'}->request($req); |
61
|
|
|
|
|
|
|
$self->{'reply'} = $res->as_string; |
62
|
|
|
|
|
|
|
$self->{'base'} = $res->base; |
63
|
|
|
|
|
|
|
sleep($self->{'sleep'}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
return $self->{'reply'}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub reply { |
69
|
|
|
|
|
|
|
my ($self) = @_; |
70
|
|
|
|
|
|
|
return $self->{'reply'}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my (@currentlinks) = (); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub callback { |
76
|
|
|
|
|
|
|
my($tag, %attr) = @_; |
77
|
|
|
|
|
|
|
local($_); |
78
|
|
|
|
|
|
|
return if ($tag ne 'a' && $tag ne 'frame'); # we only look closer at |
79
|
|
|
|
|
|
|
foreach (values %attr) { |
80
|
|
|
|
|
|
|
if (!/^mailto:/) { |
81
|
|
|
|
|
|
|
s/\#.*?$//; |
82
|
|
|
|
|
|
|
push (@currentlinks, $_); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my($p) = HTML::LinkExtor->new(\&callback); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub extract_hrefs { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
my $regexp = shift; |
92
|
|
|
|
|
|
|
@currentlinks = (); |
93
|
|
|
|
|
|
|
$p->parse($self->{'reply'}); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
@currentlinks = map { $_ = URI::URL::url($_, $self->{'base'})->abs; } |
96
|
|
|
|
|
|
|
@currentlinks; |
97
|
|
|
|
|
|
|
if (defined($regexp) && |
98
|
|
|
|
|
|
|
$regexp ne "") { |
99
|
|
|
|
|
|
|
@currentlinks = grep (/$regexp/, @currentlinks); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
return (@currentlinks); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub extract_data { |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
my $regexp = shift; |
107
|
|
|
|
|
|
|
my $replyin = shift; |
108
|
|
|
|
|
|
|
my (@returnval); |
109
|
|
|
|
|
|
|
my ($reply) = defined($replyin) ? $replyin : |
110
|
|
|
|
|
|
|
$self->{'reply'}; |
111
|
|
|
|
|
|
|
while ($reply =~ m/$regexp/is) { |
112
|
|
|
|
|
|
|
push (@returnval, $1); |
113
|
|
|
|
|
|
|
$reply = $::POSTMATCH; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
return @returnval; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub dump_links { |
119
|
|
|
|
|
|
|
my ($self, @list) = @_; |
120
|
|
|
|
|
|
|
my ($href); |
121
|
|
|
|
|
|
|
foreach $href (@list) { |
122
|
|
|
|
|
|
|
if ($self->{'found'}->{$href} != 1) { |
123
|
|
|
|
|
|
|
$self->{'found'}->{$href} = 1; |
124
|
|
|
|
|
|
|
$self->print (">> $href\n"); |
125
|
|
|
|
|
|
|
$self->print ( $self->load($href)); |
126
|
|
|
|
|
|
|
$self->flush(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub print { |
132
|
|
|
|
|
|
|
my ($self, $s) = @_; |
133
|
|
|
|
|
|
|
$self->{'output_handle'}->print($s); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub flush { |
137
|
|
|
|
|
|
|
my ($self, $s) = @_; |
138
|
|
|
|
|
|
|
$self->{'output_handle'}->flush(); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub output_handle { |
144
|
|
|
|
|
|
|
my ($self, $outh) = @_; |
145
|
|
|
|
|
|
|
$self->{'output_handle'} = $outh; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub extract_cycle { |
149
|
|
|
|
|
|
|
my ($self, $href, $elements, $cycle_regexp, |
150
|
|
|
|
|
|
|
$extract_regexp, $row) = @_; |
151
|
|
|
|
|
|
|
my (@courselist) = (); |
152
|
|
|
|
|
|
|
my ($pageindex) = 1; |
153
|
|
|
|
|
|
|
while (1) { |
154
|
|
|
|
|
|
|
my (%hash) = %$elements; |
155
|
|
|
|
|
|
|
$hash{$row} = $pageindex; |
156
|
|
|
|
|
|
|
my ($reply) = |
157
|
|
|
|
|
|
|
$self->load($href, \%hash); |
158
|
|
|
|
|
|
|
push (@courselist, |
159
|
|
|
|
|
|
|
$self->extract_hrefs($extract_regexp)); |
160
|
|
|
|
|
|
|
if ($reply =~ /$cycle_regexp/i) { |
161
|
|
|
|
|
|
|
print "# Found next", "\n"; |
162
|
|
|
|
|
|
|
$pageindex += $1; |
163
|
|
|
|
|
|
|
} else { |
164
|
|
|
|
|
|
|
last; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
return @courselist; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=pod |
172
|
|
|
|
|
|
|
Backward conpatibility with GnaCatalog::Load |
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub extract { |
176
|
|
|
|
|
|
|
print STDERR "Warning: extract is depreciated, use extract_hrefs"; |
177
|
|
|
|
|
|
|
my ($self, $get, $post); |
178
|
|
|
|
|
|
|
$self->load($get, $post); |
179
|
|
|
|
|
|
|
return $self->extract_hrefs(); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=pod |
183
|
|
|
|
|
|
|
Backward conpatibility with GnaCatalog::Load |
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
package GnaCatalog::Load; |
187
|
|
|
|
|
|
|
@GnaCatalog::Load::ISA = qw(GnaData::Load); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub new { |
190
|
|
|
|
|
|
|
print STDERR "Warning: GnaCatalog::Load is depreciated use GnaCatalog::Load"; |
191
|
|
|
|
|
|
|
return GnaCatalog::Load::new(@_); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|