use warnings;
use strict;
-use WWW::Mechanize;
use MARC::Record;
use Data::Dump qw/dump/;
-binmode STDOUT, ':utf8';
+use base 'Scraper';
my $cobiss_marc21 = {
'010' => { a => [ '020', 'a' ] },
},
205 => { a => [ 250 , 'a' ] },
210 => {
- a => [ 250 , 'a' ],
- c => [ 250 , 'b' ],
- d => [ 250 , 'c' ],
+ a => [ 260 , 'a' ],
+ c => [ 260 , 'b' ],
+ d => [ 260 , 'c' ],
},
215 => {
a => [ 300 , 'a' ],
},
};
-our $mech = WWW::Mechanize->new();
-our $hits;
-
sub diag {
print "# ", @_, $/;
}
# @attr 1=1007 standard-id
# @attr 1=1016 any
-our $usemap = {
+sub usemap {{
8 => 'BN', # FIXME check
7 => 'SN', # FIXME check
4 => 'TI',
# 1007 => '',
# 1016 => '',
-};
-
-sub usemap {
- my $f = shift || die;
- $usemap->{$f};
-}
+}};
sub search {
my ( $self, $query ) = @_;
diag "get $url";
+ my $mech = $self->{mech} || die "no mech?";
+
+ my $hits;
$mech->get( $url );
diag "got session";
diag "in COMARC format";
$mech->follow_link( url_regex => qr/fmt=13/ );
+
+ return $hits;
}
-sub fetch_rec {
+sub next_marc {
my ($self,$format) = @_;
+ my $mech = $self->{mech} || die "no mech?";
+
$format ||= 'unimarc';
die "unknown format: $format" unless $format =~ m{(uni|us)marc};
my $marc = MARC::Record->new;
+ $comarc =~ s/[\r\n]+\s{5}//gs; # join continuation lines
+warn "## comarc join: $comarc\n";
+
foreach my $line ( split(/[\r\n]+/, $comarc) ) {
if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
}
}
- my $path = "marc/$id.$format";
-
- open($out, '>:utf8', $path);
- print $out $marc->as_usmarc;
- close($out);
-
- diag "created $path ", -s $path, " bytes";
-
+ $self->save_marc( $id, $marc->as_usmarc );
diag $marc->as_formatted;
$nr++;