line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ex:ts=8 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::Scraper::ISBN::TWApexbook_Driver; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2151
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
71
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
WWW::Scraper::ISBN::TWApexbook_Driver - Search driver for TWApexbook's online catalog. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
See parent class documentation (L) |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Searches for book information from the TWApexbook's online catalog. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
########################################################################### |
30
|
|
|
|
|
|
|
#Library Modules # |
31
|
|
|
|
|
|
|
########################################################################### |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
6
|
use WWW::Scraper::ISBN::Driver; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
34
|
1
|
|
|
1
|
|
1212
|
use WWW::Mechanize; |
|
1
|
|
|
|
|
286068
|
|
|
1
|
|
|
|
|
46
|
|
35
|
1
|
|
|
1
|
|
2731
|
use Template::Extract; |
|
1
|
|
|
|
|
720
|
|
|
1
|
|
|
|
|
28
|
|
36
|
1
|
|
|
1
|
|
904
|
use Text::Iconv; |
|
1
|
|
|
|
|
4367
|
|
|
1
|
|
|
|
|
64
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
########################################################################### |
39
|
|
|
|
|
|
|
#Constants # |
40
|
|
|
|
|
|
|
########################################################################### |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
7
|
use constant QUERY => 'http://www.apexbook.com.tw/index.php?php_mode=search&isbn=%s'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
325
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
########################################################################### |
47
|
|
|
|
|
|
|
#Inheritence # |
48
|
|
|
|
|
|
|
########################################################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
@ISA = qw(WWW::Scraper::ISBN::Driver); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
########################################################################### |
53
|
|
|
|
|
|
|
#Interface Functions # |
54
|
|
|
|
|
|
|
########################################################################### |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over 4 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item C |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Creates a query string, then passes the appropriate form fields to the Apexbook |
63
|
|
|
|
|
|
|
server. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The returned page should be the correct catalog page for that ISBN. If not the |
66
|
|
|
|
|
|
|
function returns zero and allows the next driver in the chain to have a go. If |
67
|
|
|
|
|
|
|
a valid page is returned, the following fields are returned via the book hash: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
isbn |
70
|
|
|
|
|
|
|
title |
71
|
|
|
|
|
|
|
author |
72
|
|
|
|
|
|
|
book_link |
73
|
|
|
|
|
|
|
image_link |
74
|
|
|
|
|
|
|
pubdate |
75
|
|
|
|
|
|
|
publisher |
76
|
|
|
|
|
|
|
price_sell |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The book_link and image_link refer back to the Apexbook website. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub search { |
85
|
1
|
|
|
1
|
1
|
2004
|
my $self = shift; |
86
|
1
|
|
|
|
|
2
|
my $isbn = shift; |
87
|
1
|
|
|
|
|
867
|
$self->found(0); |
88
|
1
|
|
|
|
|
848
|
$self->book(undef); |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
18
|
my $url = sprintf(QUERY, $isbn); |
91
|
1
|
|
|
|
|
11
|
my $mechanize = WWW::Mechanize->new(); |
92
|
1
|
|
|
|
|
28057
|
$mechanize->get($url); |
93
|
1
|
50
|
|
|
|
4693554
|
return undef unless($mechanize->success()); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
24
|
my $template = <
|
96
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
title="[% title %]">[% ... %] |
99
|
|
|
|
|
|
|
作者:[% author %]">[% ... %] |
100
|
|
|
|
|
|
|
ISBN:[% isbn %]">[% ... %] |
101
|
|
|
|
|
|
|
出版商:[% publisher %]">[% ... %] |
102
|
|
|
|
|
|
|
出版日期:[% pubdate %]">[% ... %] |
103
|
|
|
|
|
|
|
售價:[% price_sell %]"> |
104
|
|
|
|
|
|
|
END |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
92
|
my $extract = Template::Extract->new; |
107
|
1
|
|
|
|
|
56485
|
my $content = Text::Iconv->new("utf-8", "big5")->convert($mechanize->content()); |
108
|
1
|
|
|
|
|
419
|
my $data = $extract->extract($template, $content); |
109
|
|
|
|
|
|
|
|
110
|
1
|
50
|
|
|
|
7611
|
return $self->handler("Could not extract data from TWApexbook result page.") |
111
|
|
|
|
|
|
|
unless(defined $data); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $bk = { |
114
|
|
|
|
|
|
|
'isbn' => $data->{isbn}, |
115
|
|
|
|
|
|
|
'title' => $data->{title}, |
116
|
|
|
|
|
|
|
'author' => $data->{author}, |
117
|
|
|
|
|
|
|
'book_link' => $url, |
118
|
|
|
|
|
|
|
'image_link' => "http://www.apexbook.com.tw/bookcovers/Covers/$isbn.jpg", |
119
|
|
|
|
|
|
|
'pubdate' => $data->{pubdate}, |
120
|
|
|
|
|
|
|
'publisher' => $data->{publisher}, |
121
|
|
|
|
|
|
|
'price_sell' => $data->{price_sell}, |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->book($bk); |
125
|
0
|
|
|
|
|
|
$self->found(1); |
126
|
0
|
|
|
|
|
|
return $self->book; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
__END__ |