support multiple results
authordpavlin <dpavlin@ae73d1a6-5fa4-44a9-8f13-f281fb455051>
Sat, 20 Jun 2009 22:09:33 +0000 (22:09 +0000)
committerdpavlin <dpavlin@ae73d1a6-5fa4-44a9-8f13-f281fb455051>
Sat, 20 Jun 2009 22:09:33 +0000 (22:09 +0000)
git-svn-id: svn+ssh://llin.lib/home/dpavlin/private/svn/Z3950-HTML-Scraper@8 ae73d1a6-5fa4-44a9-8f13-f281fb455051

COBISS.pm
server.pl

index d7628b5..f3c698d 100644 (file)
--- a/COBISS.pm
+++ b/COBISS.pm
@@ -5,7 +5,6 @@ use strict;
 
 use WWW::Mechanize;
 use MARC::Record;
-use File::Slurp;
 
 binmode STDOUT, ':utf8';
 
@@ -119,7 +118,7 @@ sub fetch_marc {
 
        my $comarc;
 
-       if ( $mech->content =~ m{<pre>\s*(.+?(\d+\.)\s+ID=(\d+).+?)\s*</pre>}s ) {
+       if ( $mech->content =~ m{<pre>\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*</pre>}s ) {
 
                my $comarc = $1;
                my $nr = $2;
@@ -131,7 +130,9 @@ diag "fetch_marc $nr [$id]";
                $comarc =~ s{<font[^>]*>}{<s>}gs;
                $comarc =~ s{</font>}{<e>}gs;
 
-               write_file "comarc/$id", $comarc;
+               open(my $out, '>:utf8', "comarc/$id");
+               print $out $comarc;
+               close($out);
 
                print $comarc;
 
@@ -158,6 +159,9 @@ diag "fetch_marc $nr [$id]";
 
                diag $marc->as_formatted;
 
+               $nr++;
+               $mech->follow_link( url_regex => qr/rec=$nr/ );
+
                return $marc->as_usmarc;
        } else {
                die "can't fetch COMARC format from ", $mech->content;
index 0cfce93..6d26b06 100755 (executable)
--- a/server.pl
+++ b/server.pl
@@ -49,7 +49,8 @@ diag "search for $query";
         $this->{ERR_CODE} = 108;
         return;
     }
-    my $hits = $CROBISS::hits || diag "no results for $query";
+    my $hits = $COBISS::hits || diag "no results for $query";
+diag "got $hits hits";
     my $rs   = {
         lower => 1,
         upper => $hits < $max_records ? $max_records : $hits,