line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::ValentinskaCZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
26038
|
use base qw(WWW::Search); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1884
|
|
5
|
3
|
|
|
3
|
|
288800
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
100
|
|
6
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
88
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
1847
|
use Encode qw(decode_utf8); |
|
3
|
|
|
|
|
24081
|
|
|
3
|
|
|
|
|
265
|
|
10
|
3
|
|
|
3
|
|
24
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
67
|
|
11
|
3
|
|
|
3
|
|
1407
|
use Readonly; |
|
3
|
|
|
|
|
7014
|
|
|
3
|
|
|
|
|
149
|
|
12
|
3
|
|
|
3
|
|
1297
|
use Text::Iconv; |
|
3
|
|
|
|
|
6255
|
|
|
3
|
|
|
|
|
117
|
|
13
|
3
|
|
|
3
|
|
1437
|
use Web::Scraper; |
|
3
|
|
|
|
|
98107
|
|
|
3
|
|
|
|
|
19
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constants. |
16
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $VALENTINSKA_CZ => 'http://valentinska.cz/'; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $VALENTINSKA_CZ_ACTION1 => 'index.php?hledani=Vyhledej&hltex='; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Version. |
21
|
|
|
|
|
|
|
our $VERSION = 0.02; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Setup. |
24
|
|
|
|
|
|
|
sub native_setup_search { |
25
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
26
|
|
|
|
|
|
|
$self->{'_def'} = scraper { |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Get list of books. |
29
|
|
|
|
|
|
|
process '//table[@class="ProductTable"]/tr/td', |
30
|
|
|
|
|
|
|
'books[]' => scraper { |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
process '//h2/a', 'title' => 'TEXT'; |
33
|
0
|
|
|
|
|
|
process '//h2/a', 'url' => '@href'; |
34
|
0
|
|
|
|
|
|
process '//img', 'cover_url' => '@src'; |
35
|
0
|
|
|
|
|
|
process '//p[@class="AuthorName"]', |
36
|
|
|
|
|
|
|
'author' => 'TEXT'; |
37
|
0
|
|
|
|
|
|
process '//p[@class="BookPrice"]/span', |
38
|
|
|
|
|
|
|
'price' => 'TEXT'; |
39
|
0
|
|
|
|
|
|
return; |
40
|
0
|
|
|
0
|
|
|
}; |
41
|
0
|
|
|
|
|
|
return; |
42
|
0
|
|
|
|
|
|
}; |
43
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
44
|
0
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Get data. |
48
|
|
|
|
|
|
|
sub native_retrieve_some { |
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Query. |
52
|
0
|
|
|
|
|
|
my $i1 = Text::Iconv->new('utf-8', 'windows-1250'); |
53
|
0
|
|
|
|
|
|
my $query = $i1->convert(decode_utf8($self->{'_query'})); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Get content. |
56
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
57
|
|
|
|
|
|
|
'agent' => "WWW::Search::KacurCZ/$VERSION", |
58
|
|
|
|
|
|
|
); |
59
|
0
|
|
|
|
|
|
my $response = $ua->get($VALENTINSKA_CZ. |
60
|
|
|
|
|
|
|
$VALENTINSKA_CZ_ACTION1.$query, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Process. |
64
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
65
|
0
|
|
|
|
|
|
my $i2 = Text::Iconv->new('windows-1250', 'utf-8'); |
66
|
0
|
|
|
|
|
|
my $content = $i2->convert($response->content); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Get books structure. |
69
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Process each book. |
72
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'url'); |
74
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'cover_url'); |
75
|
0
|
|
|
|
|
|
$self->_remove_tr($book_hr, 'title'); |
76
|
0
|
|
|
|
|
|
push @{$self->{'cache'}}, $book_hr; |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Fix URL to absolute path. |
84
|
|
|
|
|
|
|
sub _fix_url { |
85
|
0
|
|
|
0
|
|
|
my ($book_hr, $url) = @_; |
86
|
0
|
0
|
|
|
|
|
if (exists $book_hr->{$url}) { |
87
|
0
|
|
|
|
|
|
$book_hr->{$url} = $VALENTINSKA_CZ.$book_hr->{$url}; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Remove trailing whitespace. |
93
|
|
|
|
|
|
|
sub _remove_tr { |
94
|
0
|
|
|
0
|
|
|
my ($self, $book_hr, $key) = @_; |
95
|
0
|
0
|
|
|
|
|
if (! exists $book_hr->{$key}) { |
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
$book_hr->{$key} =~ s/^\s+//gms; |
99
|
0
|
|
|
|
|
|
$book_hr->{$key} =~ s/\s+$//gms; |
100
|
0
|
|
|
|
|
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |