9 binmode STDOUT, ':utf8';
12 '010' => { a => [ '020', 'a' ] },
17 205 => { a => [ 250 , 'a' ] },
35 my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
39 my $mech = WWW::Mechanize->new();
42 warn "# got session\n";
44 $mech->follow_link( text_regex => qr/union/ );
46 warn "# submit search\n";
55 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
58 warn "get't find results in ", $mech->content;
61 warn "# got $hits results, get first one\n";
63 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
65 warn "# in COMARC format\n";
67 $mech->follow_link( url_regex => qr/fmt=13/ );
71 if ( $mech->content =~ m{<pre>\s*(.+1\..+?)\s*</pre>}s ) {
73 $comarc =~ s{</?b>}{}gs;
74 $comarc =~ s{<font[^>]*>}{<s>}gs;
75 $comarc =~ s{</font>}{<e>}gs;
79 my $marc = MARC::Record->new;
81 foreach my $line ( split(/[\r\n]+/, $comarc) ) {
84 if ( $line !~ s{(\d\d\d)([01 ])([01 ])}{} ) {
90 sub sf { warn "sf",@_,"|",@f; push @f, @_; }
91 $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
92 warn "# f:", join(' ', @f), " left:|$line|\n";
93 $marc->add_fields( @f );
97 open(my $out, '>:utf8', 'out.marc');
98 print $out $marc->as_usmarc;
101 warn $marc->as_formatted;
105 die "can't fetch COMARC format from ", $mech->content;