#!/usr/bin/env perl # htid2txt.pl - given a HathiTrust identifier, output a plain (OCRed) text # Eric Lease Morgan # (c) University of Notre Dame; distributed under a GNU Public License # February 10, 2019 - first cut # configure use constant KEY => ''; use constant SECRET => ''; use constant OCRREQUEST => 'https://babel.hathitrust.org/cgi/htd/volume/pageocr/'; use constant HTID => 'uva.x000274833'; # require use strict; use OAuth::Lite::Consumer; use OAuth::Lite::AuthMethod; # initialize my $consumer = OAuth::Lite::Consumer->new( consumer_key => KEY, consumer_secret => SECRET, auth_method => OAuth::Lite::AuthMethod::URL_QUERY, ); # continually get pages my $continue = 1; my $page = 0; my $ocrrequest = OCRREQUEST . HTID; while ( $continue ) { # increment and build request url $page++; my $url = $ocrrequest . '/' . $page; # request my $response = $consumer->request( method => 'GET', url => $url, params => { v => '2' } ); # output, conditionally if ( $response->code == '404' ) { last } else { print $response->content, "\n" } } # done exit;