line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ex:ts=8 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::Scraper::ISBN::TWTenlong_Driver; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
725
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
72
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
WWW::Scraper::ISBN::TWTenlong_Driver - Search driver for TWTenlong'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 TWTenlong'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
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
34
|
1
|
|
|
1
|
|
1747
|
use WWW::Mechanize; |
|
1
|
|
|
|
|
258363
|
|
|
1
|
|
|
|
|
138
|
|
35
|
1
|
|
|
1
|
|
1094
|
use Template::Extract; |
|
1
|
|
|
|
|
763
|
|
|
1
|
|
|
|
|
27
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
1126
|
use Data::Dumper; |
|
1
|
|
|
|
|
7518
|
|
|
1
|
|
|
|
|
87
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
########################################################################### |
40
|
|
|
|
|
|
|
#Constants # |
41
|
|
|
|
|
|
|
########################################################################### |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
10
|
use constant TENLONG => 'http://www.tenlong.com.tw'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
461
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
########################################################################### |
48
|
|
|
|
|
|
|
#Inheritence # |
49
|
|
|
|
|
|
|
########################################################################### |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
@ISA = qw(WWW::Scraper::ISBN::Driver); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
########################################################################### |
54
|
|
|
|
|
|
|
#Interface Functions # |
55
|
|
|
|
|
|
|
########################################################################### |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over 4 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item C |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a query string, then passes the appropriate form fields to the Tenlong |
64
|
|
|
|
|
|
|
server. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The returned page should be the correct catalog page for that ISBN. If not the |
67
|
|
|
|
|
|
|
function returns zero and allows the next driver in the chain to have a go. If |
68
|
|
|
|
|
|
|
a valid page is returned, the following fields are returned via the book hash: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
isbn |
71
|
|
|
|
|
|
|
title |
72
|
|
|
|
|
|
|
author |
73
|
|
|
|
|
|
|
pages |
74
|
|
|
|
|
|
|
book_link |
75
|
|
|
|
|
|
|
image_link |
76
|
|
|
|
|
|
|
pubdate |
77
|
|
|
|
|
|
|
publisher |
78
|
|
|
|
|
|
|
price_list |
79
|
|
|
|
|
|
|
price_sell |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The book_link and image_link refer back to the Tenlong website. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub search { |
88
|
1
|
|
|
1
|
1
|
2205
|
my $self = shift; |
89
|
1
|
|
|
|
|
5
|
my $isbn = shift; |
90
|
1
|
|
|
|
|
9
|
$self->found(0); |
91
|
1
|
|
|
|
|
29
|
$self->book(undef); |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
16
|
my $mechanize = WWW::Mechanize->new(); |
94
|
1
|
|
|
|
|
30411
|
$mechanize->get(TENLONG); |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
1726176
|
$mechanize->submit_form( |
97
|
|
|
|
|
|
|
form_name => 'BookSearchForm', |
98
|
|
|
|
|
|
|
fields => { |
99
|
|
|
|
|
|
|
fKeyword => $isbn, |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# The Search Results page |
104
|
0
|
|
|
|
|
|
my $template = <
|
105
|
|
|
|
|
|
|
關鍵字查詢結果[% ... %] |
106
|
|
|
|
|
|
|
END |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $extract = Template::Extract->new; |
109
|
0
|
|
|
|
|
|
my $data = $extract->extract($template, $mechanize->content()); |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
return $self->handler("Could not extract data from TWTenlong result page.") |
112
|
|
|
|
|
|
|
unless(defined $data); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $book = $data->{book}; |
115
|
0
|
|
|
|
|
|
$mechanize->get($book); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$template = <
|
118
|
|
|
|
|
|
|
[% ... %] |
119
|
|
|
|
|
|
|
[% title %][% ... %] |
120
|
|
|
|
|
|
|
by [% author %] | [% ... %]
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
ISBN :[% ... %] [% isbn %] | [% ... %]
123
|
|
|
|
|
|
|
出版商 :[% ... %] [% publisher %] | [% ... %]
124
|
|
|
|
|
|
|
出版日期 :[% ... %] [% pubdate %] | [% ... %]
125
|
|
|
|
|
|
|
頁數 :[% ... %] [% pages %] | [% ... %]
126
|
|
|
|
|
|
|
定價 :[% ... %]">[% price_list %][% ... %] |
127
|
|
|
|
|
|
|
售價 :[% ... %]">[% price_sell %] |
128
|
|
|
|
|
|
|
END |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$data = $extract->extract($template, $mechanize->content()); |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
return $self->handler("Could not extract data from TWTenlong result page.") |
133
|
|
|
|
|
|
|
unless(defined $data); |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $bk = { |
136
|
|
|
|
|
|
|
'isbn' => $data->{isbn}, |
137
|
|
|
|
|
|
|
'title' => $data->{title}, |
138
|
|
|
|
|
|
|
'author' => $data->{author}, |
139
|
|
|
|
|
|
|
'pages' => $data->{pages}, |
140
|
|
|
|
|
|
|
'book_link' => TENLONG.$book, |
141
|
|
|
|
|
|
|
'image_link' => TENLONG."/BookSearch/".$data->{image_link}, |
142
|
|
|
|
|
|
|
'pubdate' => $data->{pubdate}, |
143
|
|
|
|
|
|
|
'publisher' => $data->{publisher}, |
144
|
|
|
|
|
|
|
'price_list' => $data->{price_list}, |
145
|
|
|
|
|
|
|
'price_sell' => $data->{price_sell}, |
146
|
|
|
|
|
|
|
}; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$self->book($bk); |
149
|
0
|
|
|
|
|
|
$self->found(1); |
150
|
0
|
|
|
|
|
|
return $self->book; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
__END__ |