/[Z3950-HTML-Scraper]/COBISS.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /COBISS.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by dpavlin, Sat Jun 20 19:42:00 2009 UTC revision 7 by dpavlin, Sat Jun 20 20:19:49 2009 UTC
# Line 76  sub search { Line 76  sub search {
76    
77          my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';          my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
78    
79  diag "# get $url";  diag "get $url";
80    
81          $mech->get( $url );          $mech->get( $url );
82    
83  diag "# got session";  diag "got session";
84    
85          $mech->follow_link( text_regex => qr/union/ );          $mech->follow_link( text_regex => qr/union/ );
86    
87  diag "# switch to advanced form (select)";  diag "switch to advanced form (select)";
88    
89          $mech->follow_link( url_regex => qr/mode=3/ );          $mech->follow_link( url_regex => qr/mode=3/ );
90    
91  diag "# submit search $query";  diag "submit search $query";
92    
93          $mech->submit_form(          $mech->submit_form(
94                  fields => {                  fields => {
# Line 104  diag "# submit search $query"; Line 104  diag "# submit search $query";
104                  return;                  return;
105          }          }
106    
107  diag "# got $hits results, get first one";  diag "got $hits results, get first one";
108    
109          $mech->follow_link( url_regex => qr/ukaz=DISP/ );          $mech->follow_link( url_regex => qr/ukaz=DISP/ );
110    
111  diag "# in COMARC format";  diag "in COMARC format";
112    
113          $mech->follow_link( url_regex => qr/fmt=13/ );          $mech->follow_link( url_regex => qr/fmt=13/ );
114  }  }
# Line 125  sub fetch_marc { Line 125  sub fetch_marc {
125                  my $nr = $2;                  my $nr = $2;
126                  my $id = $3;                  my $id = $3;
127    
128  diag "# fetch_marc $nr [$id]";  diag "fetch_marc $nr [$id]";
129    
130                  $comarc =~ s{</?b>}{}gs;                  $comarc =~ s{</?b>}{}gs;
131                  $comarc =~ s{<font[^>]*>}{<s>}gs;                  $comarc =~ s{<font[^>]*>}{<s>}gs;
# Line 138  diag "# fetch_marc $nr [$id]"; Line 138  diag "# fetch_marc $nr [$id]";
138                  my $marc = MARC::Record->new;                  my $marc = MARC::Record->new;
139    
140                  foreach my $line ( split(/[\r\n]+/, $comarc) ) {                  foreach my $line ( split(/[\r\n]+/, $comarc) ) {
                         our @f;  
141    
142                          if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {                          if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
143                                  diag "SKIP: $line";                                  diag "SKIP: $line";
144                          } else {                          } else {
145                                  $line .= "<eol>";                                  $line .= "<eol>";
146    
147                                  @f = ( $1, $2, $3 );                                  our @f = ( $1, $2, $3 );
148                                  sub sf { push @f, @_; }                                  sub sf { push @f, @_; }
149                                  $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;                                  $line =~ s{<s>(\w)<e>([^<]+)\s*}{sf($1, $2)}ges;
150                                  diag "# f:", join('|', @f), " left: |$line|";                                  diag "f:", join('|', @f), " left: |$line|";
151                                  $marc->add_fields( @f );                                  $marc->add_fields( @f );
152                          }                          }
153                  }                  }

Legend:
Removed from v.5  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26