7 use Data::Dump qw/dump/;
13 my $debug = $ENV{DEBUG} || 0;
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
45 my ( $self, $query ) = @_;
47 die "need query" unless defined $query;
49 # http://catalog.hathitrust.org/Search/Home?lookfor=croatia%20AND%20zagreb&type=title
50 my $url = 'http://catalog.hathitrust.org/Search/Home?lookfor=' . $query;
54 $self->mech->get( $url );
58 if ( $self->mech->content =~ m{of\s*<span class="strong">(\d+)</span>\s*Results for}s ) {
61 diag "get't find results in ", $self->mech->content;
65 diag "got $hits results";
67 $self->populate_records;
69 return $self->{hits} = $hits;
72 sub populate_records {
75 foreach my $link ( $self->mech->find_all_links( url_regex => qr{/Record/\d+} ) ) {
77 push @{ $self->{records} }, $url;
83 my ($self,$format) = @_;
87 my $url = shift @{ $self->{records} };
90 diag "fetch next page";
92 $self->mech->follow_link( text_regex => qr/Next/ );
93 $self->populate_records;
94 $url = shift @{ $self->{records} };
96 warn "ERROR no more results\n";
101 my $id = $1 if $url =~ m{Record/(\d+)};
103 $self->mech->get( $url . '.mrc' );
105 my $marc = decode('utf-8', $self->mech->content );
107 $self->save_marc( "$id.marc", $marc );
109 $self->mech->back; # return to search results for next page