line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::GalerieIlonkaCZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
26639
|
use base qw(WWW::Search); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1896
|
|
5
|
3
|
|
|
3
|
|
264700
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
86
|
|
6
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
81
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
1837
|
use Encode qw(decode_utf8); |
|
3
|
|
|
|
|
23696
|
|
|
3
|
|
|
|
|
230
|
|
10
|
3
|
|
|
3
|
|
19
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
50
|
|
11
|
3
|
|
|
3
|
|
1412
|
use Readonly; |
|
3
|
|
|
|
|
6917
|
|
|
3
|
|
|
|
|
137
|
|
12
|
3
|
|
|
3
|
|
1512
|
use Web::Scraper; |
|
3
|
|
|
|
|
97593
|
|
|
3
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $GILONKA_CZ => 'http://www.galerie-ilonka.cz'; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $GILONKA_CZ_ACTION1 => '/galerie-ilonka/0/0/3/42/9/0/?hledatjak=2'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Version. |
20
|
|
|
|
|
|
|
our $VERSION = 0.01; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Setup. |
23
|
|
|
|
|
|
|
sub native_setup_search { |
24
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
25
|
|
|
|
|
|
|
$self->{'_def'} = scraper { |
26
|
|
|
|
|
|
|
process '//div[@id="incenterpage2"]/div'. |
27
|
|
|
|
|
|
|
'/div[@class="productBody"]', 'books[]' => scraper { |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
process '//div[@class="productTitle"]/div/a', |
30
|
|
|
|
|
|
|
'title' => 'TEXT'; |
31
|
|
|
|
|
|
|
# XXX Jak vybrat podtitul, kdyz tam je. Treba pri vyhledavani exlibris |
32
|
|
|
|
|
|
|
# process '//div[@class="productTitle"]/div', |
33
|
|
|
|
|
|
|
# 'subtitle' => 'RAW'; |
34
|
0
|
|
|
|
|
|
process '//div[@class="img_box"]/a', 'url' => '@href'; |
35
|
0
|
|
|
|
|
|
process '//div[@class="productText"]', |
36
|
|
|
|
|
|
|
'description' => 'TEXT'; |
37
|
|
|
|
|
|
|
# XXX Cannot parse . Breaks everything after this. |
38
|
0
|
|
|
|
|
|
process '//div[@class="productPriceBox"]'. |
39
|
|
|
|
|
|
|
'/div[@class="productPrice"]'. |
40
|
|
|
|
|
|
|
'/span[@itemprop="price"]', 'price' => 'TEXT'; |
41
|
0
|
|
|
|
|
|
process '//div[@class="img_box"]/a/img', |
42
|
|
|
|
|
|
|
'cover_url' => '@src'; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return; |
45
|
0
|
|
|
0
|
|
|
}; |
46
|
0
|
|
|
|
|
|
return; |
47
|
0
|
|
|
|
|
|
}; |
48
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
49
|
0
|
|
|
|
|
|
return 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Get data. |
53
|
|
|
|
|
|
|
sub native_retrieve_some { |
54
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Query. |
57
|
0
|
|
|
|
|
|
my $query = decode_utf8($self->{'_query'}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Get content. |
60
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
61
|
|
|
|
|
|
|
'agent' => "WWW::Search::GalerieIlonkaCZ/$VERSION", |
62
|
|
|
|
|
|
|
); |
63
|
0
|
|
|
|
|
|
my $response = $ua->get($GILONKA_CZ.$GILONKA_CZ_ACTION1."&slovo=$query"); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Process. |
66
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
67
|
0
|
|
|
|
|
|
my $content = $response->content; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Get books structure. |
70
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Process each book. |
73
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'url'); |
75
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'cover_url'); |
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} = $GILONKA_CZ.$book_hr->{$url}; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |