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
44 And => '&bool[]=AND&',
48 my ( $prefix, $term ) = @_;
49 return 'type[]=' . $prefix . '&lookfor[]=' . $term;
54 my ( $self, $query ) = @_;
56 die "need query" unless defined $query;
58 # http://catalog.hathitrust.org/Search/Home?lookfor=croatia%20AND%20zagreb&type=title
59 my $url = 'http://catalog.hathitrust.org/Search/Home?' . $query;
63 $self->mech->get( $url );
67 if ( $self->mech->content =~ m{of\s*<span class="strong">(\d+)</span>\s*Results for}s ) {
70 diag "get't find results in ", $self->mech->content;
74 diag "got $hits results";
76 $self->populate_records;
78 return $self->{hits} = $hits;
81 sub populate_records {
84 foreach my $link ( $self->mech->find_all_links( url_regex => qr{/Record/\d+} ) ) {
86 push @{ $self->{records} }, $url;
92 my ($self,$format) = @_;
96 my $url = shift @{ $self->{records} };
99 diag "fetch next page";
101 $self->mech->follow_link( text_regex => qr/Next/ );
102 $self->populate_records;
103 $url = shift @{ $self->{records} };
105 warn "ERROR no more results\n";
110 my $id = $1 if $url =~ m{Record/(\d+)};
112 $self->mech->get( $url . '.mrc' );
114 my $marc = decode('utf-8', $self->mech->content );
116 $self->save_marc( "$id.marc", $marc );
118 $self->mech->back; # return to search results for next page