On Thu, Aug 21, 2003 at 12:10:52PM -0500, Bill White wrote: > Is there an easy perl way to retrieve a MARC record for a given ISBN?
As others have noted this is just what Z39.50 is built for. But if you are in the mood to try an unorthodox approach (at least for the sake of seeing a relatively new and useful CPAN module in action), you might want to try to use WWW::Mechanize to create a bot that searches for the ISBN at catalog.loc.gov and pulls down the MARC record. Just such a bot is listed below. WWW::Mechanize is really useful for this sort of work, and is extremely handy for writing automated tests, which make sure your web applications are working properly...so you can rest easy while your computer works hard :) //Ed -- #!/usr/bin/perl use strict; use WWW::Mechanize; my $isbn = shift; ## create a robot to go to loc and search for the isbn my $robot = WWW::Mechanize->new(); $robot->get( 'http://catalog.loc.gov' ); $robot->follow_link( n => 7 ); $robot->field( 'Search_Arg', $isbn ); $robot->field( 'Search_Code', 'KNUM' ); $robot->submit(); ## look for failure if ( $robot->content() =~ /the system failed/i ) { print "LoC site says the system failed...\n"; exit(1); } elsif ( $robot->content() =~ /found no results/i ) { print "ISBN $isbn not found at LoC...\n"; exit(1); } ## need to remove the MAILADDY field from the form or else ## things don't work right my $form = $robot->current_form(); my @inputs = grep { $_->{ name } !~ /MAILADDY/ } $form->inputs(); $form->{ inputs } = [EMAIL PROTECTED]; ## select the radio button for MARC records and click SAVE $robot->field( 'RD' => 1 ); $robot->click( 'SAVE' ); ## output if it looks like we found it my $marc = $robot->content(); if ( $robot !~ /\n/ ) { print $marc; } else { print "ISBN $isbn not found\n"; }