line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::Antikvariat11CZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
46388
|
use base qw(WWW::Search); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2317
|
|
5
|
3
|
|
|
3
|
|
353437
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
110
|
|
6
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
109
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
16
|
use HTTP::Cookies; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
61
|
|
10
|
3
|
|
|
3
|
|
13
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
52
|
|
11
|
3
|
|
|
3
|
|
2025
|
use Readonly; |
|
3
|
|
|
|
|
8820
|
|
|
3
|
|
|
|
|
184
|
|
12
|
3
|
|
|
3
|
|
1766
|
use Web::Scraper; |
|
3
|
|
|
|
|
130023
|
|
|
3
|
|
|
|
|
23
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $ANTIKVARIAT11_CZ => 'http://antikvariat11.cz'; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $ANTIKVARIAT11_CZ_ACTION1 => '/hledani'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Version. |
20
|
|
|
|
|
|
|
our $VERSION = 0.01; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Setup. |
23
|
|
|
|
|
|
|
sub native_setup_search { |
24
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
25
|
0
|
|
|
|
|
|
$self->{'_cookie'} = HTTP::Cookies->new( |
26
|
|
|
|
|
|
|
'autosave' => 1, |
27
|
|
|
|
|
|
|
'file' => "$ENV{'HOME'}/.cookies.txt", |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
$self->{'_def'} = scraper { |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Link to next page. |
32
|
0
|
|
|
0
|
|
|
process '//ul[@class="pager"]/li/a', 'next_page' => '@href'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Get list of books. |
35
|
|
|
|
|
|
|
process '//div[@id="content"]/div[@id]', 'books[]' => scraper { |
36
|
0
|
|
|
|
|
|
process '//div/h3', 'title' => 'TEXT'; |
37
|
0
|
|
|
|
|
|
process '//div/h3/a', 'detailed_link' => '@href'; |
38
|
0
|
|
|
|
|
|
process '//div[@class="para-au"]/span', |
39
|
|
|
|
|
|
|
'author' => 'TEXT'; |
40
|
0
|
|
|
|
|
|
process '//div[@class="para-ill"]/span', |
41
|
|
|
|
|
|
|
'illustrator' => 'TEXT'; |
42
|
0
|
|
|
|
|
|
process '//div[@class="para-pg"]/span', |
43
|
|
|
|
|
|
|
'pages' => 'RAW'; |
44
|
0
|
|
|
|
|
|
process '//div[@class="para-issued"]/span', |
45
|
|
|
|
|
|
|
'year_issued' => 'TEXT'; |
46
|
0
|
|
|
|
|
|
process '//div[@class="para-cat"]/span', |
47
|
|
|
|
|
|
|
'category' => 'TEXT'; |
48
|
0
|
|
|
|
|
|
process '//div[@class="para-state"]/span', |
49
|
|
|
|
|
|
|
'stay' => 'TEXT'; |
50
|
0
|
|
|
|
|
|
process '//div[@class="para-price"]/span', |
51
|
|
|
|
|
|
|
'price' => 'TEXT'; |
52
|
0
|
|
|
|
|
|
process '//div/img', 'image' => '@src'; |
53
|
0
|
|
|
|
|
|
return; |
54
|
0
|
|
|
|
|
|
}; |
55
|
0
|
|
|
|
|
|
return; |
56
|
0
|
|
|
|
|
|
}; |
57
|
0
|
|
|
|
|
|
$self->{'_offset'} = 0; |
58
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
59
|
0
|
|
|
|
|
|
$self->{'ua'} = LWP::UserAgent->new( |
60
|
|
|
|
|
|
|
'agent' => "WWW::Search::Antikvariat11CZ/$VERSION", |
61
|
|
|
|
|
|
|
'cookie_jar' => $self->{'_cookie'}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Get for root for cookie. |
65
|
0
|
|
|
|
|
|
$self->{'ua'}->get($ANTIKVARIAT11_CZ); |
66
|
0
|
|
|
|
|
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Get data. |
70
|
|
|
|
|
|
|
sub native_retrieve_some { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Get content. |
74
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post($ANTIKVARIAT11_CZ. |
75
|
|
|
|
|
|
|
$ANTIKVARIAT11_CZ_ACTION1, |
76
|
|
|
|
|
|
|
'Content' => { |
77
|
|
|
|
|
|
|
'q' => $self->{'_query'}, |
78
|
|
|
|
|
|
|
'Submit' => 'hledat', |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Process. |
83
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
84
|
0
|
|
|
|
|
|
my $content = $response->content; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Get books structure. |
87
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Process each book. |
90
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'detailed_link'); |
92
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'image'); |
93
|
0
|
|
|
|
|
|
push @{$self->{'cache'}}, $book_hr; |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Next url. |
97
|
0
|
|
|
|
|
|
_fix_url($books_hr, 'next_page'); |
98
|
0
|
|
|
|
|
|
$self->next_url($books_hr->{'next_page'}); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Fix URL to absolute path. |
105
|
|
|
|
|
|
|
sub _fix_url { |
106
|
0
|
|
|
0
|
|
|
my ($book_hr, $url) = @_; |
107
|
0
|
0
|
|
|
|
|
if (exists $book_hr->{$url}) { |
108
|
0
|
|
|
|
|
|
$book_hr->{$url} = $ANTIKVARIAT11_CZ.$book_hr->{$url}; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |