/[webpac2]/trunk/bin/isi-download-results.pl
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 /trunk/bin/isi-download-results.pl

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

revision 1332 by dpavlin, Sun Apr 18 11:04:49 2010 UTC revision 1336 by dpavlin, Tue Jun 29 18:32:27 2010 UTC
# Line 12  use Text::Unaccent; Line 12  use Text::Unaccent;
12  # http://images.isiknowledge.com/WOK46/help/WOS/h_advanced_examples.html  # http://images.isiknowledge.com/WOK46/help/WOS/h_advanced_examples.html
13    
14  our $q = 'AD=Croatia';  our $q = 'AD=Croatia';
15    $q = 'CA=BRATKO, D';
16    
17  my $range_size = 500;  my $range_size = 500;
18  my $overlap    = 3; # between previous and this range  my $overlap    = 3; # between previous and this range
19  my $skip_results = 0;  
20    my $results = 0;
21    my $citations = 0;
22    my $cited_reference = 0; # html tables
23    my $citing_articles = 1; # as many files as cited articles
24    
25  my $cites_by_year = 0;  my $cites_by_year = 0;
26    
27  my $max_cites = 5000; # ISI limit to get cites  my $max_cites = 5000; # ISI limit to get cites
28    
 if ( 0 ) {  
         $q = 'TS=psychology AND AD=Croatia';  
         $range_size = 50;  
         $overlap    = 0;  
         $max_cites  = 50;  
 }  
   
29  $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;  $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;
30    
31    warn "QUERY: $q\n";
32    
33  our $mech = WWW::Mechanize->new(  our $mech = WWW::Mechanize->new(
34          autocheck => 1,          autocheck => 0, # it dies in reference download with it!
35          cookie_jar => undef,          cookie_jar => undef,
36  );  );
37    
# Line 118  sub get_results { Line 120  sub get_results {
120                          last;                          last;
121                  }                  }
122    
123                    if ( $mech->content =~ m{Please wait while your request is processed} ) {
124                            warn "WARNING: processing request";
125                    }
126    
127    
128                  my $path = "/tmp/isi.$q.$from-$to";                  my $path = "/tmp/isi.$q.$from-$to";
129                  $path .= '.' . $desc if $desc;                  $path .= '.' . $desc if $desc;
# Line 211  sub years { Line 217  sub years {
217          return $years;          return $years;
218  }  }
219    
220  search;  if ( $results ) {
221  years;          search;
222  get_results unless $skip_results;          years;
223            get_results;
224    }
225    
226    if ( $citations ) {
227    
228  citations;          citations;
229            years unless @ranges;
230    
231  do {          do {
232          my $part;                  my $part;
233          if ( @ranges ) {                  if ( @ranges ) {
234                  $part .= $ranges[0]->[0] . '.';                          $part .= $ranges[0]->[0] . '.';
235                  search;                          search;
236                  citations;                          citations;
237          }                  }
238          $part .= 'citing';                  $part .= 'citing';
239          get_results $part;                  get_results $part;
240  } while ( @ranges );          } while ( @ranges );
241    
242    }
243    
244    if ( $q =~ m{CA=(.+)} && $cited_reference ) {
245    
246            my $CA = $1;
247    
248            warn "# citated reference search";
249            $mech->follow_link( url_regex => qr/CitedReferenceSearch/ );
250            save_mech;
251    
252    
253            $mech->submit_form(
254                    form_name => 'WOS_CitedReferenceSearch_input_form',
255                    fields => {
256                            'value(input1)' => $CA,
257                    },
258            );
259    
260            my $page = 1;
261            my $records = $1 if $mech->content =~ m/(\d+)\s+records/;
262            warn "# found $records records\n";
263            my $last_span = 'fake';
264    
265            while (1) {
266                    save_mech "/tmp/isi.$q.citedref.$page";
267    
268                    $page++;
269    
270                    $mech->submit_form(
271                            form_name => 'summary_navigation',
272                            fields => {
273                                    'page' => $page,
274                            },
275                    );
276    
277                    $mech->form_name( 'summary_navigation' );
278                    last if $mech->value('page') < $page;
279    
280                    if ( $mech->content =~ m/(\d+\s*-\s*(\d+))/ ) {
281                            warn "span: $1\n";
282                            last if $2 == $records;
283                            last if $1 == $last_span;
284                            $last_span = $1;
285                    } elsif ( $page > 5 ) {
286                            warn "ARTIFICALLY LIMITED TO 5 PAGES WITHOUT VALID SPAN!";
287                            last;
288                    }
289    
290            }
291    
292    }
293    
294    if ( $q =~ m{CA=(.+)} && $citing_articles ) {
295    
296            search;
297    
298            my $orig_q = $q;
299            my $nr = 0;
300    
301            foreach my $link ( $mech->find_all_links( url_regex => qr/CitingArticles.do/ ) ) {
302                    $nr++;
303                    warn "link $nr\n";
304                    $mech->get( $link->url );
305                    save_mech;
306                    $q = $orig_q . '.citing_article.' . $nr;
307                    get_results;
308                    $mech->back;
309                    save_mech;
310                    $mech->back;
311                    save_mech;
312            }
313    
314            $q = $orig_q;
315    }
316    
317    warn "OVER\n";

Legend:
Removed from v.1332  
changed lines
  Added in v.1336

  ViewVC Help
Powered by ViewVC 1.1.26