line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Scraper::Delicious; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34396
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1470
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
73932
|
|
|
1
|
|
|
|
|
1547
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
12
|
0
|
|
|
|
|
|
my $self = {}; |
13
|
0
|
0
|
|
|
|
|
limit($self, $args{limit}) if $args{limit}; |
14
|
0
|
0
|
|
|
|
|
ua($self, $args{ua}) if $args{ua}; |
15
|
0
|
0
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new() unless $self->{ua}; |
16
|
0
|
|
|
|
|
|
bless($self, $class); |
17
|
0
|
|
|
|
|
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub getlinks { |
21
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
22
|
0
|
0
|
|
|
|
|
return unless $path; |
23
|
0
|
0
|
|
|
|
|
my $url = ($path =~ /^htt/ ? $path |
|
|
0
|
|
|
|
|
|
24
|
|
|
|
|
|
|
: ( $path =~ /^\// ? "http://del.icio.us$path" |
25
|
|
|
|
|
|
|
: "http://del.icio.us/$path" ) ); |
26
|
0
|
|
0
|
|
|
|
my $limit = $self->{limit} || 0; |
27
|
0
|
|
|
|
|
|
my %linkset = _scrape($self->{ua}, $url, $limit); |
28
|
0
|
|
|
|
|
|
return %linkset; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub getlinksarray { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
33
|
0
|
|
|
|
|
|
my %linkset = getlinks($self, $path); |
34
|
0
|
0
|
|
|
|
|
return unless keys %linkset; |
35
|
0
|
|
|
|
|
|
my @table = sort { $b->[5] cmp $a->[5] } |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
map { [ $linkset{$_}{id}, |
37
|
|
|
|
|
|
|
$linkset{$_}{url}, |
38
|
|
|
|
|
|
|
$linkset{$_}{desc}, |
39
|
|
|
|
|
|
|
$linkset{$_}{notes}, |
40
|
|
|
|
|
|
|
$linkset{$_}{pop}, |
41
|
|
|
|
|
|
|
$linkset{$_}{date}, |
42
|
|
|
|
|
|
|
$linkset{$_}{tag}, $linkset{$_} ] |
43
|
|
|
|
|
|
|
} keys %linkset; |
44
|
0
|
|
|
|
|
|
return @table; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ua { |
48
|
0
|
|
|
0
|
1
|
|
my ($self, $ua) = @_; |
49
|
0
|
0
|
0
|
|
|
|
$self->{ua} = $ua if defined $ua |
50
|
|
|
|
|
|
|
&& ref($ua) eq 'LWP::UserAgent'; |
51
|
0
|
|
|
|
|
|
return $self->{ua}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub limit { # limit of 0 is default (unlimited) |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $limit) = @_; |
56
|
0
|
0
|
0
|
|
|
|
$self->{limit} = $limit if defined $limit && $limit =~ /^\d+$/; |
57
|
0
|
|
|
|
|
|
return $self->{limit}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub dumplink { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $linkref) = @_; |
62
|
0
|
0
|
|
|
|
|
return unless $linkref; |
63
|
0
|
0
|
|
|
|
|
$linkref = $linkref->[7] if ref($linkref) eq 'ARRAY'; |
64
|
0
|
0
|
|
|
|
|
return unless $linkref->{id}; |
65
|
0
|
|
|
|
|
|
my $str = " id = ".$linkref->{id}."\n"; |
66
|
0
|
|
|
|
|
|
$str .= " url = ".$linkref->{url}."\n"; |
67
|
0
|
0
|
|
|
|
|
$str .= " desc = ".$linkref->{desc}."\n" if $linkref->{desc}; |
68
|
0
|
0
|
|
|
|
|
$str .= "notes = ".$linkref->{notes}."\n" if $linkref->{notes}; |
69
|
0
|
0
|
|
|
|
|
$str .= " pop = ".$linkref->{pop}."\n" if $linkref->{pop}; |
70
|
0
|
0
|
|
|
|
|
$str .= " date = ".$linkref->{date}."\n" if $linkref->{date}; |
71
|
0
|
0
|
|
|
|
|
$str .= " tags = ".join(', ', sort keys %{$linkref->{tag}})."\n" |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if $linkref->{tag}; |
73
|
0
|
|
|
|
|
|
return $str; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _scrape { |
77
|
0
|
|
|
0
|
|
|
my ($ua, $url, $limit) = @_; |
78
|
0
|
|
|
|
|
|
my (%linkset, $page); |
79
|
0
|
|
|
|
|
|
my $num = 0; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
while (1) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
my $url = "$url?setcount=100" . ($page ? "&page=$page" : ''); |
84
|
0
|
|
|
|
|
|
my $rs = $ua->get($url); |
85
|
0
|
0
|
|
|
|
|
return unless $rs->is_success; |
86
|
0
|
|
|
|
|
|
my $html = $rs->content; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @tmp = split /
89
|
0
|
|
|
|
|
|
for my $scrap (@tmp[1..$#tmp]) { |
90
|
0
|
|
|
|
|
|
$scrap =~ s/\s*<\/li>.*$//si; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
next unless (my ($id, $url, $desc) = $scrap =~ |
93
|
|
|
|
|
|
|
/^(.*?)".*?a href="(.*?)".*?>(.*?)<\/a>/si) == 3; |
94
|
0
|
|
|
|
|
|
$linkset{$id} = { id => $id, url => $url, desc => $desc }; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my ($notes) = $scrap =~ /class="notes">(.*?)<\/p>/si; |
97
|
0
|
0
|
|
|
|
|
$linkset{$id}{notes} = $notes if $notes; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
for my $str (split /
|
100
|
0
|
0
|
|
|
|
|
next unless my($tag) = $str =~ /^href=.*?>(.*?)<\/a>/; |
101
|
0
|
|
|
|
|
|
$linkset{$id}{tag}{$tag}++; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
0
|
|
|
|
|
delete $linkset{$id}{tag} unless keys %{$linkset{$id}{tag}}; |
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my ($pop) = $scrap =~ /a class="pop".*?>.*?by (\d+) /si; |
106
|
0
|
0
|
|
|
|
|
$linkset{$id}{pop} = $pop if $pop; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my ($date) = $scrap =~ / class="date" title="(.*?)"/si; |
109
|
0
|
0
|
|
|
|
|
$linkset{$id}{date} = $date if $date; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
last if ++$num == $limit; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
last unless my($page0,$page1) = $html =~ / page (\d+) of (\d+)/si; |
115
|
0
|
0
|
|
|
|
|
last if $page0 == $page1; |
116
|
0
|
0
|
|
|
|
|
$page = $page ? $page + 1 : 2; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return %linkset; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
__END__ |