8 use Data::Dump qw/dump/;
10 binmode STDOUT, ':utf8';
12 our $mech = WWW::Mechanize->new();
21 # Bib-1 @and @and @and @and @and @and @and @or
27 # @attr 1=21 subject-holding
28 # @attr 1=12 control-no
29 # @attr 1=1007 standard-id
32 # LCC - Klasifikacija Kongresne knjižnice
33 # LCN - Signatura Kongresne knjižnice
34 # DDC - Deweyjeva klasifikacija
39 # SRS - Nakladnička cjelina
42 # WTI - Riječi u polju naslova
43 # WAU - Riječi u polju autora
44 # WPE - Riječi u polju individualnog autora
45 # WCO - Riječi u polju korporativnog autora
46 # WME - Riječi u polju sastanka
47 # WUT - Riječi u polju jedinstvenog naslova
48 # WPL - Riječi u polju mjesta izdavanja
49 # WPU - Riječi u polju nakladnika
50 # WSU - Riječi u polju predmetnica
51 # WSM - Riječi u predmetnicama MeSH-a
52 # WST - Riječi u polju status
53 # WGA - Riječi u geografskim odrednicama
54 # WYR - Godina izdavanja
75 my ( $self, $query ) = @_;
77 die "need query" unless defined $query;
79 my $url = 'http://161.53.240.197:8991/F?RN=' . rand(1000000000);
80 # fake JavaScript code on page which creates random session
86 diag "advanced search";
88 $mech->follow_link( url_regex => qr/find-c/ );
90 diag "submit search $query";
99 if ( $mech->content =~ m{ukupno\s+(\d+).*(do\s+(\d+))}s ) {
101 $hits = $2 if $2 && $2 < $1; # correct for max. results
103 diag "get't find results in ", $mech->content;
107 diag "got $hits results, get first one";
109 $mech->follow_link( url_regex => qr/set_entry=000001/ );
111 diag "in MARC format";
113 $mech->follow_link( url_regex => qr/format=001/ );
118 my ($self,$format) = @_;
120 print $mech->content;
122 if ( $mech->content =~ m{Zapis\s+(\d+)}s ) {
128 my $marc = MARC::Record->new;
130 my $html = $mech->content;
135 $v =~ s/\Q \E/ /gs;
138 my ($i1,$i2) = (' ',' ');
139 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)?(.)?/$1/;
140 my @sf = split(/\|/, $v);
142 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
143 diag "sf = ", dump(@sf);
144 $marc->add_fields( $f, $i1, $i2, @sf ) if $f =~ m/^\d+$/;
147 $html =~ s|<tr>\s*<td class=td1 id=bold[^>]*>(.+?)</td>\s*<td class=td1>(.+?)</td>|field($1,$2)|ges;
150 my $id = $hash->{SYS} || die "no SYS";
154 my $path = "marc/$id.$format";
156 open(my $out, '>:utf8', $path);
157 print $out $marc->as_usmarc;
160 diag "created $path ", -s $path, " bytes";
162 diag $marc->as_formatted;
166 die if $nr == 3; # FIXME
168 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
170 return $marc->as_usmarc;
172 die "can't fetch COMARC format from ", $mech->content;