/[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 1300 by dpavlin, Sat Sep 19 23:49:04 2009 UTC revision 1336 by dpavlin, Tue Jun 29 18:32:27 2010 UTC
# Line 3  Line 3 
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6    use WWW::Mechanize;
7    use Data::Dump qw(dump);
8    use File::Path;
9    use Text::Unaccent;
10    
11  # Advanced search syntax:  # Advanced search syntax:
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 = 1;  
20  my $cites_by_year = 1;  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;
26    
27  my $max_cites = 5000; # ISI limit to get cites  my $max_cites = 5000; # ISI limit to get cites
28    
29  if ( 0 ) {  $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;
         $q = 'TS=psychology AND AD=Croatia';  
         $range_size = 50;  
         $overlap    = 0;  
         $max_cites  = 50;  
 }  
30    
31  use WWW::Mechanize;  warn "QUERY: $q\n";
 use Data::Dump qw(dump);  
 use File::Path;  
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 34  our $step = 0; Line 39  our $step = 0;
39  our @ranges;  our @ranges;
40    
41  my $dir = '/tmp/isi/';  my $dir = '/tmp/isi/';
42  rmtree $dir if -e $dir;  #rmtree $dir if -e $dir;
43  mkdir $dir;  mkdir $dir unless -d $dir;
44    
45  sub save_mech {  sub save_mech {
46          my $path = shift;          my $path = shift;
# Line 115  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 208  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;
229            years unless @ranges;
230    
231  citations;          do {
232                    my $part;
233                    if ( @ranges ) {
234                            $part .= $ranges[0]->[0] . '.';
235                            search;
236                            citations;
237                    }
238                    $part .= 'citing';
239                    get_results $part;
240            } while ( @ranges );
241    
242  do {  }
243          my $part;  
244          if ( @ranges ) {  if ( $q =~ m{CA=(.+)} && $cited_reference ) {
245                  $part .= $ranges[0]->[0] . '.';  
246                  search;          my $CA = $1;
247                  citations;  
248          }          warn "# citated reference search";
249          $part .= 'citing';          $mech->follow_link( url_regex => qr/CitedReferenceSearch/ );
250          get_results $part;          save_mech;
251  } while ( @ranges );  
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.1300  
changed lines
  Added in v.1336

  ViewVC Help
Powered by ViewVC 1.1.26