download also citing articles
[webpac2] / bin / isi-download-results.pl
index 7141e6d..8ea5c32 100755 (executable)
@@ -3,18 +3,17 @@
 use warnings;
 use strict;
 
-my $q = 'TS=psychology AND AD=Croatia';
-my $range_size = 50;
+my $q = 'AD=Croatia';
+my $range_size = 500;
 
 my $dump = @ARGV ? 1 : 0;
 
-$q = 'AD=Croatia';
-$range_size = 500;
+$q = 'TS=psychology AND AD=Croatia';
 
 use WWW::Mechanize;
 use Data::Dump qw/dump/;
 
-my $mech = WWW::Mechanize->new(
+our $mech = WWW::Mechanize->new(
        autocheck => 1,
        cookie_jar => undef,
 );
@@ -51,42 +50,62 @@ warn "# summary";
 $mech->follow_link( url_regex => qr/summary/ );
 save_mech $mech;
 
-my $from = 1;
+sub get_results {
+       my $q = shift;
+       my $from = 1;
 
-while ( $from ) {
+       while ( 1 ) {
 
-       my $to = $from + $range_size;
+               my $to = $from + $range_size;
 
-       $mech->submit_form(
-               form_name => 'summary_output_form',
-               fields => {
-                       record_select_type => 'range',
-                       mark_from => $from,
-                       mark_to => $to,
-                       mark_id => 'WOS',
+               $mech->submit_form(
+                       form_name => 'summary_output_form',
+                       fields => {
+                               record_select_type => 'range',
+                               mark_from => $from,
+                               mark_to => $to,
+                               mark_id => 'WOS',
 
-                       qo_fields => 'fullrecord',
-                       citedref => 'citedref',
+                               qo_fields => 'fullrecord',
+                               citedref => 'citedref',
 
-                       save_options => 'plain_text',
+                               save_options => 'plain_text',
 
-                       fields => 'Full',
-                       format => 'save',
-               },
-               button => 'save',
-       );
-       save_mech $mech;
+                               fields => 'Full',
+                               format => 'save',
+                       },
+                       button => 'save',
+               );
+               save_mech $mech;
 
-       last if $mech->content =~ m{invalid API call};
+               if ( $mech->content =~ m{invalid API call} ) {
+                       $mech->back;
+                       return;
+               }
 
-       warn "# save_file";
-       $mech->follow_link( url_regex => qr/save_file/ );
-       save_mech $mech => "/tmp/isi.$q.$from-$to.txt";
+               warn "# save_file $from - $to [$q]";
+               $mech->follow_link( url_regex => qr/save_file/ );
+               save_mech $mech => "/tmp/isi.$q.$from-$to.txt";
 
-       $from += $range_size;
+               $from += $range_size;
 
-       $mech->back;
-       $mech->back;
-       #save_mech $mech;
+               $mech->back;
+               $mech->back;
+               #save_mech $mech;
+
+       } # while
 
 }
+
+get_results $q;
+
+save_mech $mech;
+warn "# citations";
+$mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
+save_mech $mech;
+
+$mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
+save_mech $mech;
+
+get_results $q . '.citing';
+