Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How to pull author, title using ISBN (WWW::Scraper::ISBN)?

by Perl300 (Pilgrim)
on Apr 15, 2019 at 19:45 UTC ( #1232602=perlquestion: print w/replies, xml ) Need Help??
Perl300 has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to use WWW::Scraper::ISBN to pull details like author and title of a book using it's ISBN.

The code example from modules documentation is throwing error on perl 5.28.1

#!~/perl5/perlbrew/perls/perl-5.28.1/bin/perl use Modern::Perl '2019'; use WWW::Scraper::ISBN; # instantiate the object my $scraper = WWW::Scraper::ISBN->new(); # load the drivers. requires that # WWW::Scraper::ISBN::LOC_Driver and # WWW::Scraper::ISBN::ISBNnu_Driver # be installed $scraper->drivers("LOC", "ISBNnu"); my @isbns = [ "9780134511184" ]; foreach my $num (@isbns) { $scraper->isbn($num); $scraper->search($scraper->isbn); if ($scraper->found) { my $b = $scraper->book; print "Title: ".$b->{'title'}."\n"; print "Author: ".$b->{'author'}."\n\n"; } else { print "Book: ".$scraper->isbn." not found.\n\n"; } }

The above code gives error:

Can't locate object method "isbn" via package "WWW::Scraper::ISBN" at isbn_lookup.pl line 18.

I though this might be because "isbn" method was not present in "WWW::Scraper::ISBN" module (perl module documentation on Meta CPAN). I found that method in Business::ISBN module.

Also there was mention of "Business::ISBN" module in "WWW::Scraper::ISBN" module's documentation. So I added

use Business::ISBN and changed $scraper->isbn($num); to $scraper->Business::ISBN::isbn($num);

But it still throws same error.

What am I missing here? Is there any other/better way to get book details like Title/Author using ISBN?

Replies are listed 'Best First'.
Re: How to pull author, title using ISBN (WWW::Scraper::ISBN)?
by NetWallah (Canon) on Apr 15, 2019 at 20:44 UTC
    I agree with hippo - the "Code example" looks bogus.

    There IS an "isbn" method in package WWW::Scraper::ISBN::Record , that is used to define a new record - but is probably not useful for your case.

    For your case, I would try (UNTESTED):

    my @isbns = ( "9780134511184" ); for my $num (@isbns) { my $record = $scraper->search($isbn); if($record->found) { ....

                    "It's ten o'clock... Do you know where your AI programs are?"

Re: How to pull author, title using ISBN (WWW::Scraper::ISBN)?
by hippo (Canon) on Apr 15, 2019 at 19:59 UTC
    my @isbns = [ "9780134511184" ];

    That looks pretty suspect. Can you explain why you are storing an arrayref in an array?

    I've not used this module but would probably work along the lines shown in the synopsis. The code example given later in the POD seems rather dubious by contrast.

Re: How to pull author, title using ISBN (WWW::Scraper::ISBN)?
by salva (Abbot) on Apr 16, 2019 at 08:08 UTC
Re: How to pull author, title using ISBN (WWW::Scraper::ISBN)?
by Perl300 (Pilgrim) on Apr 15, 2019 at 20:48 UTC

    Thank you for pointing that out hippo and NetWallah. I did make use of the synopsis and it gives new error now.

    Code:

    #!~/perl5/perlbrew/perls/perl-5.28.1/bin/perl use Modern::Perl; use WWW::Scraper::ISBN; my $scraper = WWW::Scraper::ISBN->new(); $scraper->drivers("LOC", "ISBNnu"); my $isbn = "9780134511184"; my $record = $scraper->search($isbn); if($record->found) { print "Book ".$record->isbn." found by driver ".$record->found_in. +"\n"; my $book = $record->book; print $book->{'title'}; print $book->{'author'}; } else { print $record->error; }

    Error:

    Cannot start LOC query session. isbn.nu website appears to be unavailable.

    I checked and found that https://www.isbn.nu is working and I can search same ISBN there without any issue. I found the error is coming from ~/perlbrew/perls/perl-5.28.1/lib/site_perl/5.28.1/WWW/Scraper/ISBN/ISBNnu_Driver.pm So I am checking that code to see if I can change something there to make it working.

    Here is the code that's generating this error:

    sub search { my ($self,$isbn) = @_; my %data; $self->found(0); $self->book(undef); my $post_url = "https://isbn.nu/".$isbn; my $mech = WWW::Mechanize->new(); $mech->agent_alias( 'Linux Mozilla' ); $mech->add_header( 'Accept-Encoding' => undef ); eval { $mech->get( $post_url ) }; return $self->handler("isbn.nu website appears to be unavailable." +) if($@ || !$mech->success() || !$mech->content());

    Seems one of the three conditions in if are returning true and so the error. I am testing by inserting some prints. Will share here what I find.

Re: How to pull author, title using ISBN (WWW::Scraper::ISBN)?
by Perl300 (Pilgrim) on Apr 15, 2019 at 21:31 UTC

    I don't think I can use this module :-( Is there any other way I can get books details using ISBN? Without using this module?

    Error is:

    $@: Error GETing https://isbn.nu/9780134511184: Protocol scheme 'https +' is not supported (LWP::Protocol::https not installed) at ~/perl5/pe +rlbrew/perls/perl-5.28.1/lib/site_perl/5.28.1/WWW/Scraper/ISBN/ISBNnu +_Driver.pm line 59.

    When I tried to install LWP::Protocol::https using cpanm, it failed

    $ cpanm LWP::Protocol::https --> Working on LWP::Protocol::https Fetching http://www.cpan.org/authors/id/O/OA/OALDERS/LWP-Protocol-http +s-6.07.tar.gz ... OK Configuring LWP-Protocol-https-6.07 ... OK ==> Found dependencies: IO::Socket::SSL, Mozilla::CA --> Working on IO::Socket::SSL Fetching http://www.cpan.org/authors/id/S/SU/SULLR/IO-Socket-SSL-2.066 +.tar.gz ... OK ==> Found dependencies: Net::SSLeay --> Working on Net::SSLeay Fetching http://www.cpan.org/authors/id/M/MI/MIKEM/Net-SSLeay-1.85.tar +.gz ... OK Configuring Net-SSLeay-1.85 ... OK Building and testing Net-SSLeay-1.85 ... FAIL ! Installing Net::SSLeay failed. See ~/.cpanm/work/1555361542.3618/bui +ld.log for details. Retry with --force to force install it. ! Installing the dependencies failed: Module 'Net::SSLeay' is not inst +alled ! Bailing out the installation for IO-Socket-SSL-2.066. --> Working on Mozilla::CA Fetching http://www.cpan.org/authors/id/A/AB/ABH/Mozilla-CA-20180117.t +ar.gz ... OK Configuring Mozilla-CA-20180117 ... OK Building and testing Mozilla-CA-20180117 ... OK Successfully installed Mozilla-CA-20180117 ! Installing the dependencies failed: Module 'IO::Socket::SSL' is not +installed ! Bailing out the installation for LWP-Protocol-https-6.07. 1 distribution installed
    $ cpanm Net::SSLeay --> Working on Net::SSLeay Fetching http://www.cpan.org/authors/id/M/MI/MIKEM/Net-SSLeay-1.85.tar +.gz ... OK Configuring Net-SSLeay-1.85 ... OK Building and testing Net-SSLeay-1.85 ... FAIL ! Installing Net::SSLeay failed. See ~/.cpanm/work/1555363377.6081/bui +ld.log for details. Retry with --force to force install it. $ vi ~/.cpanm/work/1555363377.6081/build.log Checking configure dependencies from META.yml Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.34) Configuring Net-SSLeay-1.85 Running Makefile.PL *** Found OpenSSL-1.0.2k installed in /usr *** Be sure to use the same compiler and options to compile your OpenS +SL, perl, and Net::SSLeay. Mixing and matching compilers is not supported.

    I tried force installing the module LWP::Protocol::HTTPS & Net::SSLeay but it fails. The log file for installation shows error about a missing C header file:

    SSLeay.xs:163:25: fatal error: openssl/err.h: No such file or director +y #include <openssl/err.h> ^ compilation terminated.

    2019-04-16 Athanasius fixed over-long code line

      Is there any other way I can get books details using ISBN? Without using this module?

      Note that both databases are not complete, and both may contain some garbage data.

      Also note that ISBNs should be unique, but they are not. I have several pairs of books with different title, different author, different content, but identical ISBNs. It seems several publishers reuse ISBNs over time.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      *** Found OpenSSL-1.0.2k installed in /usr

      SSLeay.xs:163:25: fatal error: openssl/err.h: No such file or directory

      Looks like Net::SSLeay is having trouble finding a compatible version of openssl - what operating system are you on?
        Thank you for your response bangor. I am on:
        $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.4 (Maipo)

      The README lists prerequisites, you need the appropriate development package.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1232602]
Approved by Paladin
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2019-04-20 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (108 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!