WWW::Scraper::ISBN::TWYlib_Driver - Search driver for TWYlib's online catalog.


WWW-Scraper-ISBN-TWYlib_Driver documentation Contained in the WWW-Scraper-ISBN-TWYlib_Driver distribution.

Index


Code Index:

NAME

Top

WWW::Scraper::ISBN::TWYlib_Driver - Search driver for TWYlib's online catalog.

SYNOPSIS

Top

See parent class documentation (WWW::Scraper::ISBN::Driver)

DESCRIPTION

Top

Searches for book information from the TWYlib's online catalog.

METHODS

Top

search()

Creates a query string, then passes the appropriate form fields to the Ylib 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
  ean
  title
  author
  book_link
  image_link
  pubdate
  publisher
  price_list
  price_sell

The book_link and image_link refer back to the Ylib website.

REQUIRES

Top

Requires the following modules be installed:

WWW::Scraper::ISBN::Driver, WWW::Mechanize, Template::Extract

SEE ALSO

Top

WWW::Scraper::ISBN, WWW::Scraper::ISBN::Record, WWW::Scraper::ISBN::Driver

AUTHOR

Top

Ying-Chieh Liao <ijliao@csie.nctu.edu.tw>

COPYRIGHT

Top


WWW-Scraper-ISBN-TWYlib_Driver documentation Contained in the WWW-Scraper-ISBN-TWYlib_Driver distribution.
# ex:ts=8

package WWW::Scraper::ISBN::TWYlib_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	QUERY	=> 'http://tsearch.ylib.com/tsearch/tp.asp?query=%s';

#--------------------------------------------------------------------------

###########################################################################
#Inheritence                                                              #
###########################################################################

@ISA = qw(WWW::Scraper::ISBN::Driver);

###########################################################################
#Interface Functions                                                      #
###########################################################################

sub search {
	my $self = shift;
	my $isbn = shift;
	$self->found(0);
	$self->book(undef);

	my $url = sprintf(QUERY, $isbn);
	my $mechanize = WWW::Mechanize->new();
	$mechanize->get($url);
	return undef unless($mechanize->success());

	# The Search Results page
	my $template = <<END;
®Ñ¦W[% ... %]<A HREF='[% book %]'>
END

	my $extract = Template::Extract->new;
	my $data = $extract->extract($template, $mechanize->content());

	return $self->handler("Could not extract data from TWYlib result page.")
		unless(defined $data);

	my $book = $data->{book};
	$mechanize->get($book);

	$template = <<END;
<!-- ®ÑÄy¸Ô²Ó¸ê®Æ  -->[% ... %]
<font color="#333333"><b>[% title %]</b>[% ... %]
<!--®ÑÄy«Ê­± -->[% ... %]
<IMG SRC="[% image_link %]" [% ... %]
<!-- ®ÑÄy¸Ô²Ó¸ê®Æ -->[% ... %]
<A HREF="[% ... %]">[% author %]</A> µÛ[% ... %]
ªìª©¡G[% pubdate %]¡E ¥Xª©¡G[% publisher %]<BR>[% ... %]
­¶¼Æ¡G[% pages %]­¶[% ... %]
ISBN¡G[% isbn %]    ¡D EAN¡G[% ean %]</p>[% ... %]
©w»ù¡G[% price_list %]¤¸[% ... %]
Àu´f»ù¡G[% ... %]<B>[% price_sell %]</B>
END

	$data = $extract->extract($template, $mechanize->content());

	return $self->handler("Could not extract data from TWYlib result page.")
		unless(defined $data);

	$data->{ean} =~ s/\s+$//;
	$data->{author} =~ s/\/µÛ//;
	$data->{pubdate} =~ s/\s+$//;
	$data->{publisher} =~ s/\s+$//;
	$data->{price_sell} =~ s/^\s+//;

	my $bk = {
		'isbn'		=> $data->{isbn},
		'ean'		=> $data->{ean},
		'title'		=> $data->{title},
		'author'	=> $data->{author},
		'book_link'	=> "http://www.ylib.com/search/".$book,
		'image_link'	=> "http://www.ylib.com".$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__