line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::ValentinskaCZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
2
|
|
|
2
|
|
34356
|
use base qw(WWW::Search); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2259
|
|
5
|
2
|
|
|
2
|
|
332873
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
75
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
2
|
|
|
2
|
|
2054
|
use Encode qw(decode_utf8); |
|
2
|
|
|
|
|
23999
|
|
|
2
|
|
|
|
|
166
|
|
10
|
2
|
|
|
2
|
|
17
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
11
|
2
|
|
|
2
|
|
1693
|
use Readonly; |
|
2
|
|
|
|
|
6326
|
|
|
2
|
|
|
|
|
101
|
|
12
|
2
|
|
|
2
|
|
12
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
13
|
2
|
|
|
2
|
|
1687
|
use Web::Scraper; |
|
2
|
|
|
|
|
97088
|
|
|
2
|
|
|
|
|
17
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constants. |
16
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $VALENTINSKA_CZ => 'http://www.valentinska.cz/'; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $VALENTINSKA_CZ_ACTION1 => 'index.php?route=product/search&search='; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Version. |
21
|
|
|
|
|
|
|
our $VERSION = 0.03; |
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 '//div[@class="product-inner clearfix"]', |
30
|
|
|
|
|
|
|
'books[]' => scraper { |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
process '//div[@class="wrap-infor"]/div[@class="name"]/a', |
33
|
|
|
|
|
|
|
'title' => 'TEXT'; |
34
|
|
|
|
|
|
|
process '//div[@class="wrap-infor"]/div[@class="name"]/a', |
35
|
|
|
|
|
|
|
'url' => ['@href', sub { |
36
|
0
|
|
|
|
|
|
my $url = shift; |
37
|
0
|
|
|
|
|
|
my $uri = URI->new($url); |
38
|
0
|
|
|
|
|
|
my %query = $uri->query_form; |
39
|
0
|
0
|
|
|
|
|
if (exists $query{'search'}) { |
40
|
0
|
|
|
|
|
|
delete $query{'search'}; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
$uri->query_form(\%query); |
43
|
0
|
|
|
|
|
|
return $uri->as_string; |
44
|
0
|
|
|
|
|
|
}]; |
45
|
0
|
|
|
|
|
|
process '//div[@class="image"]/a/img', |
46
|
|
|
|
|
|
|
'image' => '@src'; |
47
|
0
|
|
|
|
|
|
process '//div[@class="wrap-infor"]/div[@class="author"]', |
48
|
|
|
|
|
|
|
'author' => 'TEXT'; |
49
|
|
|
|
|
|
|
process '//div[@class="wrap-infor"]/div[@class="price"]/br/preceding-sibling::text()', |
50
|
0
|
|
|
|
|
|
'price' => ['TEXT', sub { s/^\s*(.*?)\s*$/$1/; }]; |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return; |
52
|
0
|
|
|
0
|
|
|
}; |
53
|
0
|
|
|
|
|
|
return; |
54
|
0
|
|
|
|
|
|
}; |
55
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
56
|
0
|
|
|
|
|
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Get data. |
60
|
|
|
|
|
|
|
sub native_retrieve_some { |
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Query. |
64
|
0
|
|
|
|
|
|
my $query = decode_utf8($self->{'_query'}); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Get content. |
67
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
68
|
|
|
|
|
|
|
'agent' => "WWW::Search::ValentinskaCZ/$VERSION", |
69
|
|
|
|
|
|
|
); |
70
|
0
|
|
|
|
|
|
my $query_url = $VALENTINSKA_CZ.$VALENTINSKA_CZ_ACTION1.$query; |
71
|
0
|
|
|
|
|
|
my $response = $ua->get($query_url); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Process. |
74
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
75
|
0
|
|
|
|
|
|
my $content = $response->content; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Get books structure. |
78
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Process each book. |
81
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
push @{$self->{'cache'}}, $book_hr; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |