WWW-Scraper-ISBN-BookDepository_Driver

 view release on metacpan or  search on metacpan

lib/WWW/Scraper/ISBN/BookDepository_Driver.pm  view on Meta::CPAN

package WWW::Scraper::ISBN::BookDepository_Driver;

use strict;
use warnings;

use vars qw($VERSION @ISA);
$VERSION = '0.13';

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

=head1 NAME

WWW::Scraper::ISBN::BookDepository_Driver - Search driver for The Book Depository online book catalog.

=head1 SYNOPSIS

See parent class documentation (L<WWW::Scraper::ISBN::Driver>)

=head1 DESCRIPTION

Searches for book information from The Book Depository online book catalog

=cut

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

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

use base qw(WWW::Scraper::ISBN::Driver);

###########################################################################
# Modules

use WWW::Mechanize;

###########################################################################
# Constants

use constant    REFERER    => 'http://www.bookdepository.co.uk/';
use constant    SEARCH    => 'http://www.bookdepository.co.uk/search?search=search&searchTerm=';
my ($URL1,$URL2) = ('http://www.bookdepository.co.uk/book/','/[^?]+\?b=\-3\&amp;t=\-26\#Bibliographicdata\-26');

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

###########################################################################
# Public Interface

=head1 METHODS

=over 4

=item C<search()>

Creates a query string, then passes the appropriate form fields to the 
Book Depository 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          (now returns isbn13)
  isbn10        
  isbn13
  ean13         (industry name)
  author
  title
  book_link
  image_link
  description
  pubdate
  publisher
  binding       (if known)
  pages         (if known)
  weight        (if known) (in grammes)
  width         (if known) (in millimetres)
  height        (if known) (in millimetres)

The book_link and image_link refer back to the The Book Depository website.

=back

=cut

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

    # validate and convert into EAN13 format
    my $ean = $self->convert_to_ean13($isbn);
    return $self->handler("Invalid ISBN specified")   
        if(!$ean || (length $isbn == 13 && $isbn ne $ean)
                 || (length $isbn == 10 && $isbn ne $self->convert_to_isbn10($ean)));

    my $mech = WWW::Mechanize->new();
    $mech->agent_alias( 'Windows IE 6' );
    $mech->add_header( 'Accept-Encoding' => undef );
    $mech->add_header( 'Referer' => REFERER );

#print STDERR "\n# search=[".SEARCH."$ean]\n";



( run in 0.362 second using v1.01-cache-2.11-cpan-d7f47b0818f )