line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::AntikvariatJudaicaCZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
35949
|
use base qw(WWW::Search); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3846
|
|
5
|
3
|
|
|
3
|
|
548546
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
67
|
|
6
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
99
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
14
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
58
|
|
10
|
3
|
|
|
3
|
|
3147
|
use Readonly; |
|
3
|
|
|
|
|
8676
|
|
|
3
|
|
|
|
|
138
|
|
11
|
3
|
|
|
3
|
|
2271
|
use Web::Scraper; |
|
3
|
|
|
|
|
151694
|
|
|
3
|
|
|
|
|
23
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constants. |
14
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $BASE_URL => 'http://antikvariat-judaica.cz/'; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $ACTION1 => 'search/node/'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Version. |
19
|
|
|
|
|
|
|
our $VERSION = 0.02; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Setup. |
22
|
|
|
|
|
|
|
sub _native_setup_search { |
23
|
0
|
|
|
0
|
|
|
my ($self, $query) = @_; |
24
|
|
|
|
|
|
|
$self->{'_def'} = scraper { |
25
|
|
|
|
|
|
|
process '//div[@class="content"]/dl/div', 'books[]' => scraper { |
26
|
0
|
|
|
|
|
|
process '//h2/a', 'title' => 'TEXT'; |
27
|
0
|
|
|
|
|
|
process '//h2/a', 'url' => '@href'; |
28
|
0
|
|
|
|
|
|
process '//img[@class="imagecache '. |
29
|
|
|
|
|
|
|
'imagecache-product_list"]', |
30
|
|
|
|
|
|
|
'cover_url' => '@src'; |
31
|
0
|
|
|
|
|
|
process '//div[@class="field sell-price"]', |
32
|
|
|
|
|
|
|
'price' => 'TEXT'; |
33
|
0
|
|
|
|
|
|
process '//div[@class="field '. |
34
|
|
|
|
|
|
|
'field-type-content-taxonomy '. |
35
|
|
|
|
|
|
|
'field-field-author"]', |
36
|
|
|
|
|
|
|
'author' => 'TEXT'; |
37
|
0
|
|
|
|
|
|
return; |
38
|
0
|
|
|
0
|
|
|
}; |
39
|
0
|
|
|
|
|
|
return; |
40
|
0
|
|
|
|
|
|
}; |
41
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
42
|
0
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Get data. |
46
|
|
|
|
|
|
|
sub _native_retrieve_some { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Get content. |
50
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
51
|
|
|
|
|
|
|
'agent' => "WWW::Search::AntikvariatJudaicaCZ/$VERSION", |
52
|
|
|
|
|
|
|
); |
53
|
0
|
|
|
|
|
|
my $response = $ua->get($BASE_URL.$ACTION1.$self->{'_query'}); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Process. |
56
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
57
|
0
|
|
|
|
|
|
my $content = $response->content; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Get books structure. |
60
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Process each book. |
63
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'url'); |
65
|
0
|
|
|
|
|
|
$book_hr->{'price'} =~ s/\N{U+00A0}/ /ms; |
66
|
0
|
|
|
|
|
|
$book_hr->{'price'} =~ s/^\s*Cena:\s*//ms; |
67
|
0
|
|
|
|
|
|
$book_hr->{'author'} =~ s/^\s*Autor:\s*//ms; |
68
|
0
|
|
|
|
|
|
push @{$self->{'cache'}}, $book_hr; |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Fix URL to absolute path. |
76
|
|
|
|
|
|
|
sub _fix_url { |
77
|
0
|
|
|
0
|
|
|
my ($book_hr, $url) = @_; |
78
|
0
|
0
|
|
|
|
|
if (exists $book_hr->{$url}) { |
79
|
0
|
|
|
|
|
|
$book_hr->{$url} = $BASE_URL.$book_hr->{$url}; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |