| WWW-Scraper-ISBN-TWTenlong_Driver documentation | Contained in the WWW-Scraper-ISBN-TWTenlong_Driver distribution. |
WWW::Scraper::ISBN::TWTenlong_Driver - Search driver for TWTenlong's online catalog.
See parent class documentation (WWW::Scraper::ISBN::Driver)
Searches for book information from the TWTenlong's online catalog.
search()Creates a query string, then passes the appropriate form fields to the Tenlong server.
The returned page should be the correct catalog page for that ISBN. If not the function returns zero and allows the next driver in the chain to have a go. If a valid page is returned, the following fields are returned via the book hash:
isbn title author pages book_link image_link pubdate publisher price_list price_sell
The book_link and image_link refer back to the Tenlong website.
Requires the following modules be installed:
WWW::Scraper::ISBN::Driver, WWW::Mechanize, Template::Extract
Ying-Chieh Liao <ijliao@csie.nctu.edu.tw>
Copyright (C) 2005 Ying-Chieh Liao <ijliao@csie.nctu.edu.tw>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| WWW-Scraper-ISBN-TWTenlong_Driver documentation | Contained in the WWW-Scraper-ISBN-TWTenlong_Driver distribution. |
# ex:ts=8 package WWW::Scraper::ISBN::TWTenlong_Driver; use strict; use warnings; use vars qw($VERSION @ISA); $VERSION = '0.01'; #--------------------------------------------------------------------------
#-------------------------------------------------------------------------- ########################################################################### #Library Modules # ########################################################################### use WWW::Scraper::ISBN::Driver; use WWW::Mechanize; use Template::Extract; use Data::Dumper; ########################################################################### #Constants # ########################################################################### use constant TENLONG => 'http://www.tenlong.com.tw'; #-------------------------------------------------------------------------- ########################################################################### #Inheritence # ########################################################################### @ISA = qw(WWW::Scraper::ISBN::Driver); ########################################################################### #Interface Functions # ###########################################################################
sub search { my $self = shift; my $isbn = shift; $self->found(0); $self->book(undef); my $mechanize = WWW::Mechanize->new(); $mechanize->get(TENLONG); $mechanize->submit_form( form_name => 'BookSearchForm', fields => { fKeyword => $isbn, }, ); # The Search Results page my $template = <<END; ÃöÁä¦r¬d¸ßµ²ªG[% ... %]<a href="[% book %]"> END my $extract = Template::Extract->new; my $data = $extract->extract($template, $mechanize->content()); return $self->handler("Could not extract data from TWTenlong result page.") unless(defined $data); my $book = $data->{book}; $mechanize->get($book); $template = <<END; <!-- InstanceBeginEditable name="Edit1" -->[% ... %] <font size="4"><b>[% title %]</b>[% ... %] by [% author %]</td>[% ... %] <div align="center"><img src="[% image_link %]"[% ... %] ISBN :[% ... %] [% isbn %]</td>[% ... %] ¥Xª©°Ó :[% ... %] [% publisher %]</td>[% ... %] ¥Xª©¤é´Á :[% ... %] [% pubdate %]</td>[% ... %] ¶¼Æ :[% ... %] [% pages %]</td>[% ... %] ©w»ù :[% ... %]">[% price_list %]</font>[% ... %] °â»ù :[% ... %]">[% price_sell %]</font> END $data = $extract->extract($template, $mechanize->content()); return $self->handler("Could not extract data from TWTenlong result page.") unless(defined $data); my $bk = { 'isbn' => $data->{isbn}, 'title' => $data->{title}, 'author' => $data->{author}, 'pages' => $data->{pages}, 'book_link' => TENLONG.$book, 'image_link' => TENLONG."/BookSearch/".$data->{image_link}, 'pubdate' => $data->{pubdate}, 'publisher' => $data->{publisher}, 'price_list' => $data->{price_list}, 'price_sell' => $data->{price_sell}, }; $self->book($bk); $self->found(1); return $self->book; } 1; __END__