7 use Data::Dump qw/dump/;
11 our $mech = WWW::Mechanize->new();
20 # Bib-1 @and @and @and @and @and @and @and @or
26 # @attr 1=21 subject-holding
27 # @attr 1=12 control-no
28 # @attr 1=1007 standard-id
31 # LCC - Klasifikacija Kongresne knjižnice
32 # LCN - Signatura Kongresne knjižnice
33 # DDC - Deweyjeva klasifikacija
38 # SRS - Nakladnička cjelina
41 # WTI - Riječi u polju naslova
42 # WAU - Riječi u polju autora
43 # WPE - Riječi u polju individualnog autora
44 # WCO - Riječi u polju korporativnog autora
45 # WME - Riječi u polju sastanka
46 # WUT - Riječi u polju jedinstvenog naslova
47 # WPL - Riječi u polju mjesta izdavanja
48 # WPU - Riječi u polju nakladnika
49 # WSU - Riječi u polju predmetnica
50 # WSM - Riječi u predmetnicama MeSH-a
51 # WST - Riječi u polju status
52 # WGA - Riječi u geografskim odrednicama
53 # WYR - Godina izdavanja
68 my ( $self, $query ) = @_;
70 die "need query" unless defined $query;
72 my $url = 'http://161.53.240.197:8991/F?RN=' . rand(1000000000);
73 # fake JavaScript code on page which creates random session
77 my $mech = $self->{mech} || die "no mech?";
80 diag "advanced search";
82 $mech->follow_link( url_regex => qr/find-c/ );
84 diag "submit search $query";
93 if ( $mech->content =~ m{ukupno\s+(\d+).*(do\s+(\d+))}s ) {
95 $hits = $2 if $2 && $2 < $1; # correct for max. results
97 diag "get't find results in ", $mech->content;
101 diag "got $hits results, get first one";
103 $mech->follow_link( url_regex => qr/set_entry=000001/ );
105 diag "in MARC format";
107 $mech->follow_link( url_regex => qr/format=001/ );
114 my ($self,$format) = @_;
116 my $mech = $self->{mech} || die "no mech?";
118 print $mech->content;
120 if ( $mech->content =~ m{Zapis\s+(\d+)}s ) {
126 my $marc = MARC::Record->new;
128 my $html = $mech->content;
133 $v =~ s/\Q \E/ /gs;
136 my ($i1,$i2) = (' ',' ');
137 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)?(.)?/$1/;
138 my @sf = split(/\|/, $v);
140 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
141 diag "sf = ", dump(@sf);
142 $marc->add_fields( $f, $i1, $i2, @sf ) if $f =~ m/^\d+$/;
145 $html =~ s|<tr>\s*<td class=td1 id=bold[^>]*>(.+?)</td>\s*<td class=td1>(.+?)</td>|field($1,$2)|ges;
148 my $id = $hash->{SYS} || die "no SYS";
152 my $path = "marc/$id.$format";
154 open(my $out, '>:utf8', $path);
155 print $out $marc->as_usmarc;
158 diag "created $path ", -s $path, " bytes";
160 diag $marc->as_formatted;
164 die if $nr == 3; # FIXME
166 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
168 return $marc->as_usmarc;
170 die "can't fetch COMARC format from ", $mech->content;