package WWW::Scraper::ISBN::LibUniIt_Driver;
use strict;
use warnings;
use LWP::UserAgent;
use WWW::Scraper::ISBN::Driver;
use HTML::Entities qw(decode_entities);
our @ISA = qw(WWW::Scraper::ISBN::Driver);
our $VERSION = '0.2';
sub search {
my $self = shift;
my $isbn = shift;
$self->found(0);
$self->book(undef);
my $post_url = 'http://www.libreriauniversitaria.it/c_power_search.php?shelf=BIT&q=' . $isbn . '&submit=Invia';
my $ua = new LWP::UserAgent;
my $res = $ua->get($post_url);
my $doc = $res->as_string;
my $title = "";
my $authors = "";
my $editor = "";
my $date = "";
my $price = "";
if ($doc =~ /Nessun prodotto corrisponde ai criteri di ricerca/) {
$self->error("book not found.");
$self->found(0);
return 0;
} elsif ($doc =~ m|
Ricerca - $isbn - libreriauniversitaria\.it|i){
my $info;
if ($doc =~ m|]+>]+ class="product_heading_title_link" [^>]+>([^<]+)(.*?) | |){
$title = $1;
$info = $2;
$authors = parse_authors($info);
if ($info =~ m|]+ href="libri-editore[^"]+" [^>]+/>([^<]+) - (\d+)|){
$editor = $1;
$date = $2;
}
}
$price = $1 if ($doc =~ /Prezzo: .*?€ (\d+)/);
} elsif ($doc =~ /Dettagli del libro/){
$price = $1 if ($doc =~ m|€ ([^<]+)|);
$title = $1 if ($doc =~ m|Titolo: ([^>]+)|);
$authors = parse_authors($1) if ($doc =~ m|Autor[ei]:(.*?)|);
$editor = $1 if ($doc =~ m|Editore:.*?]+/>([^<]+)|);
$date = $1 if ($doc =~ m|Data di Pubblicazione:\s+(\d+)|);
} else {
$self->error("liberiauniversitaria.it answered in an unattended way, book information cannot be found.");
$self->found(0);
};
decode_entities($title);
decode_entities($authors);
decode_entities($editor);
my $bk = {
'isbn' => $isbn,
'author' => $authors,
'title' => $title,
'editor' => $editor,
'date' => $date,
'price' => $price,
};
$self->book($bk);
$self->found(1);
return $bk;
}
sub parse_authors {
my $info = shift;
my $sep = "";
my $authors;
while ($info =~ s|]+>([^<]+)||){
$authors .= $sep . $1;
$sep = ", ";
}
return $authors;
}
1;
__END__
=head1 NAME
WWW::Scraper::ISBN::LibUniIt - Driver for L that searches L.
=head1 SYNOPSIS
See parent class documentation (L)
=head1 REQUIRES
Requires the following modules be installed:
=over 4
=item L
=item L
=item L
=back
=head1 DESCRIPTION
Searches for book information from http://www.libreriauniversitaria.it
=head1 METHODS
=over 4
=item C
Searches for an ISBN on L.
If a valid result is returned the following fields are returned:
isbn
author
title
editor
date
price
=head2 EXPORT
None by default.
=head1 SEE ALSO
=over 4
=item L<< WWW::Scraper::ISBN >>
=item L<< WWW::Scraper::ISBN::Record >>
=item L<< WWW::Scraper::ISBN::Driver >>
=back
=head1 AUTHOR
Angelo Lucia, Eangelo.lucia@email.itE
=head1 COPYRIGHT AND LICENSE
Copyright 2006 by Angelo Lucia
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut