line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Search::KacurCZ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
33937
|
use base qw(WWW::Search); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2187
|
|
5
|
3
|
|
|
3
|
|
270739
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
93
|
|
6
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
87
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
1913
|
use Encode qw(decode_utf8); |
|
3
|
|
|
|
|
24437
|
|
|
3
|
|
|
|
|
243
|
|
10
|
3
|
|
|
3
|
|
26
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
54
|
|
11
|
3
|
|
|
3
|
|
1353
|
use Readonly; |
|
3
|
|
|
|
|
7407
|
|
|
3
|
|
|
|
|
182
|
|
12
|
3
|
|
|
3
|
|
1389
|
use Text::Iconv; |
|
3
|
|
|
|
|
6802
|
|
|
3
|
|
|
|
|
121
|
|
13
|
3
|
|
|
3
|
|
1415
|
use Web::Scraper; |
|
3
|
|
|
|
|
104262
|
|
|
3
|
|
|
|
|
22
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constants. |
16
|
|
|
|
|
|
|
Readonly::Scalar our $MAINTAINER => 'Michal Spacek '; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $KACUR_CZ => 'http://kacur.cz/'; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $KACUR_CZ_ACTION1 => '/search.asp?doIt=search&menu=675&'. |
19
|
|
|
|
|
|
|
'kategorie=&nazev=&rok=&dosearch=Vyhledat'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Version. |
22
|
|
|
|
|
|
|
our $VERSION = 0.01; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Setup. |
25
|
|
|
|
|
|
|
sub native_setup_search { |
26
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
27
|
|
|
|
|
|
|
$self->{'_def'} = scraper { |
28
|
|
|
|
|
|
|
process '//div[@class="productItemX"]', 'books[]' => scraper { |
29
|
0
|
|
|
|
|
|
process '//div/h3/a', 'title' => 'TEXT'; |
30
|
0
|
|
|
|
|
|
process '//div/h3/a', 'url' => '@href'; |
31
|
0
|
|
|
|
|
|
process '//img', 'cover_url' => '@src'; |
32
|
0
|
|
|
|
|
|
process '//p', 'author_publisher[]' => 'TEXT'; |
33
|
0
|
|
|
|
|
|
process '//span[@class="price"]', 'price' => 'TEXT'; |
34
|
0
|
|
|
|
|
|
return; |
35
|
0
|
|
|
0
|
|
|
}; |
36
|
0
|
|
|
|
|
|
return; |
37
|
0
|
|
|
|
|
|
}; |
38
|
0
|
|
|
|
|
|
$self->{'_query'} = $query; |
39
|
0
|
|
|
|
|
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Get data. |
43
|
|
|
|
|
|
|
sub native_retrieve_some { |
44
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Query. |
47
|
0
|
|
|
|
|
|
my $i1 = Text::Iconv->new('utf-8', 'windows-1250'); |
48
|
0
|
|
|
|
|
|
my $query = $i1->convert(decode_utf8($self->{'_query'})); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Get content. |
51
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
52
|
|
|
|
|
|
|
'agent' => "WWW::Search::KacurCZ/$VERSION", |
53
|
|
|
|
|
|
|
); |
54
|
0
|
|
|
|
|
|
my $response = $ua->get($KACUR_CZ.$KACUR_CZ_ACTION1."&autor=$query"); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Process. |
57
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
58
|
0
|
|
|
|
|
|
my $i2 = Text::Iconv->new('windows-1250', 'utf-8'); |
59
|
0
|
|
|
|
|
|
my $content = $i2->convert($response->content); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Get books structure. |
62
|
0
|
|
|
|
|
|
my $books_hr = $self->{'_def'}->scrape($content); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Process each book. |
65
|
0
|
|
|
|
|
|
foreach my $book_hr (@{$books_hr->{'books'}}) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'url'); |
67
|
0
|
|
|
|
|
|
_fix_url($book_hr, 'cover_url'); |
68
|
0
|
|
|
|
|
|
$book_hr->{'author'} |
69
|
|
|
|
|
|
|
= $book_hr->{'author_publisher'}->[0]; |
70
|
0
|
|
|
|
|
|
$book_hr->{'author'} =~ s/\N{U+00A0}$//ms; |
71
|
0
|
|
|
|
|
|
$book_hr->{'publisher'} |
72
|
|
|
|
|
|
|
= $book_hr->{'author_publisher'}->[1]; |
73
|
0
|
|
|
|
|
|
$book_hr->{'publisher'} =~ s/\N{U+00A0}$//ms; |
74
|
0
|
|
|
|
|
|
delete $book_hr->{'author_publisher'}; |
75
|
0
|
|
|
|
|
|
($book_hr->{'old_price'}, $book_hr->{'price'}) |
76
|
|
|
|
|
|
|
= split m/\s*\*\s*/ms, $book_hr->{'price'}; |
77
|
0
|
|
|
|
|
|
push @{$self->{'cache'}}, $book_hr; |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Fix URL to absolute path. |
85
|
|
|
|
|
|
|
sub _fix_url { |
86
|
0
|
|
|
0
|
|
|
my ($book_hr, $url) = @_; |
87
|
0
|
0
|
|
|
|
|
if (exists $book_hr->{$url}) { |
88
|
0
|
|
|
|
|
|
$book_hr->{$url} = $KACUR_CZ.$book_hr->{$url}; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |