WWW::Scraper::ISBN::ISBNnu_Driver - Driver for L<WWW::Scraper::ISBN> that searches L<http://www.isbn.nu/>.


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

Index


Code Index:

NAME

Top

WWW::Scraper::ISBN::ISBNnu_Driver - Driver for WWW::Scraper::ISBN that searches http://www.isbn.nu/.

SYNOPSIS

Top

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

REQUIRES

Top

Requires the following modules be installed:

WWW::Scraper::ISBN::Driver
HTTP::Request::Common
LWP::UserAgent

DESCRIPTION

Top

Searches for book information from http://www.isbn.nu/.

METHODS

Top

clean_authors()

Cleans junk from authors field.

trim()

Trims excess whitespace.

search()

Grabs page from http://www.isbn.nu/'s handy interface and attempts to extract the desired information. If a valid result is returned the following fields are returned:

   isbn
   author
   title
   edition

EXPORT

None by default.

SEE ALSO

Top

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

No mailing list or website currently available. Primary development done through CSX ( http://csx.calvin.edu/ )

AUTHOR

Top

Andy Schamp, <andy@schamp.net>

COPYRIGHT AND LICENSE

Top


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

package WWW::Scraper::ISBN::ISBNnu_Driver;

use strict;
use warnings;
use HTTP::Request::Common;
use LWP::UserAgent;
use WWW::Scraper::ISBN::Driver;

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

our $VERSION = '0.18';

sub clean_authors {
	my $self = shift;
        my $authors_with_tags = shift;
        my @authors = split('<br>', $authors_with_tags);
        foreach my $author (@authors) {
                $author =~ s/<[^>]+>//g;
        }
        return join(", ", @authors);
}

sub trim {
	my $self = shift;
        $_ = shift;
        s/^\s+//;           # trim leading whitespace
        s/\s+$//;           # trim trailing whitespace
        s/\n//g;            # trim newlines?
        s/ +/ /g;           # trim extra middle space
        return $_;
}
                
sub search {
        my $self = shift;
        my $isbn = shift;
        $self->found(0);
        $self->book(undef);
        my $post_url = "http://isbn.nu/".$isbn;
        my $ua = new LWP::UserAgent;
        my $res = $ua->request(GET $post_url);
        my $doc = $res->as_string;
        
        my $volume = "";
        my $edition = "";
        my $title = "";
                
        if ($doc =~ /<p class="rsheadnr"><font color="#333366">([^<]+)<\/font><\/p>/) {
                $title = $self->trim($1);
        }

        if (($title eq "") || ($title eq "No Title Found")) {
		$self->found(0);
                return 0;
        } else {
		$self->found(1);
	}

        $doc =~ /<td class="smallbold" align="left" valign="top" width="35%">Authors*<\/td><td class="bodytext" align="left" valign="top">(.+)<\/td><\/tr>/;
        my $tempauthors = $1;
        my $authors = "";
        my $sep = "";
        while ($tempauthors =~ s/<a href="[^"]+">([^<]+)<\/a>(<br>)*//) {
                $authors .=  $sep.$1;
                $sep = ", ";
        }
         
        if ($doc =~ /<tr><td class="smallbold" align="left" valign="top" width="35%">Edition<\/td><td class="bodytext" align="left" valign="top">([^<]+)<\/td><\/tr>/) {
                $edition = $1;
        }
         
        if ($doc =~ /<tr><td class="smallbold" align="left" valign="top" width="35%">Volume<\/td><td class="bodytext" align="left" valign="top">([^<]+)<\/td><\/tr>/) {
                $volume = $1;
        }

        my $bk = {   
                'isbn' => $isbn,
                'author' => $authors,
                'title' => $title,
                'edition' => $edition,
        };
	$self->book($bk);
        return $bk;
}

1;
__END__
# Below is stub documentation for your module. You'd better edit it!