/[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 1282 by dpavlin, Fri Sep 18 17:46:04 2009 UTC revision 1291 by dpavlin, Sat Sep 19 15:05:12 2009 UTC
# Line 3  Line 3 
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6  my $q = 'TS=psychology AND AD=Croatia';  our $q = 'AD=Croatia';
7  my $range_size = 50;  my $range_size = 500;
8    
9  my $dump = @ARGV ? 1 : 0;  my $dump = @ARGV ? 1 : 0;
10    
11  $q = 'AD=Croatia';  $q = 'TS=psychology AND AD=Croatia';
 $range_size = 500;  
12    
13  use WWW::Mechanize;  use WWW::Mechanize;
14  use Data::Dump qw/dump/;  use Data::Dump qw(dump);
15    use File::Path;
16    
17  my $mech = WWW::Mechanize->new(  our $mech = WWW::Mechanize->new(
18          autocheck => 1,          autocheck => 1,
19          cookie_jar => undef,          cookie_jar => undef,
20  );  );
21    
22  our $step = 0;  our $step = 0;
23    
24    my $dir = '/tmp/isi/';
25    rmtree $dir if -e $dir;
26    mkdir $dir;
27    
28  sub save_mech {  sub save_mech {
29          my ( $mech, $path ) = @_;          my ( $mech, $path ) = @_;
30          $step++;          $step++;
31          $path ||= sprintf('/tmp/isi.%02d.%s', $step, $mech->{ct} =~ m{html}i ? 'html' : 'txt' );          my $base_path = sprintf('%s/%04d', $dir,$step);
32            $path ||= $base_path . ( $mech->{ct} =~ m{html}i ? '.html' : '.txt' );
33          $mech->save_content( $path );          $mech->save_content( $path );
34          warn "# [$step] $path ", -s $path, " ", $mech->ct;          warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
35          $mech->dump_all if $dump;          open(my $dump, '>', "$base_path.dump.txt");
36            $mech->dump_all($dump);
37  }  }
38    
39  warn "# get session";  warn "# get session";
40  $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );  $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
41  save_mech $mech;  save_mech $mech;
42    
43  warn "# advanced serach";  sub search {
44  $mech->follow_link( url_regex => qr/AdvancedSearch/ );          warn "# advanced serach";
45  save_mech $mech;          $mech->follow_link( url_regex => qr/AdvancedSearch/ );
46            save_mech $mech;
47    
48  warn "# cookie_jar ", dump $mech->cookie_jar;          warn "# cookie_jar ", dump $mech->cookie_jar;
49    
50            $mech->submit_form(
51                    fields => {
52                            'value(input1)' => $q,
53                    }
54            );
55            save_mech $mech;
56    
57            warn "# summary";
58            $mech->follow_link( url_regex => qr/summary/ );
59            save_mech $mech;
60    }
61    
62    sub get_results {
63            my $from = 1;
64    
65            while ( 1 ) {
66    
67                    my $to = $from + $range_size;
68    
69                    $mech->submit_form(
70                            form_name => 'summary_output_form',
71                            fields => {
72                                    record_select_type => 'range',
73                                    mark_from => $from,
74                                    mark_to => $to,
75                                    mark_id => 'WOS',
76    
77                                    qo_fields => 'fullrecord',
78                                    citedref => 'citedref',
79    
80                                    save_options => 'plain_text',
81    
82                                    fields => 'Full',
83                                    format => 'save',
84                            },
85                            button => 'save',
86                    );
87                    save_mech $mech;
88    
89                    if ( $mech->content =~ m{invalid API call} ) {
90                            $mech->back;
91                            last;
92                    }
93    
94                    warn "range $from - $to [$q]\n";
95                    $mech->follow_link( url_regex => qr/save_file/ );
96                    save_mech $mech => "/tmp/isi.$q.$from-$to.txt";
97    
98                    $from += $range_size;
99    
100                    $mech->back;
101                    $mech->back;
102                    #save_mech $mech;
103    
 $mech->submit_form(  
         fields => {  
                 'value(input1)' => $q,  
104          }          }
 );  
 save_mech $mech;  
105    
106  warn "# summary";  }
 $mech->follow_link( url_regex => qr/summary/ );  
 save_mech $mech;  
107    
 my $from = 1;  
108    
109  while ( $from ) {  sub citations {
110            save_mech $mech;
111            warn "# citation report";
112            $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
113            save_mech $mech;
114    
115          my $to = $from + $range_size;          warn "view citing articles";
116            $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
117            save_mech $mech;
118    }
119    
120          $mech->submit_form(  sub years {
121                  form_name => 'summary_output_form',          my $years_url = $mech->find_link( text_regex => qr/more options/ );
122                  fields => {          if ( ! $years_url ) {
123                          record_select_type => 'range',                  warn "W: can't find years\n";
124                          mark_from => $from,                  return;
125                          mark_to => $to,          }
126                          mark_id => 'WOS',          $years_url = $years_url->url_abs;
127            warn "## $years_url";
128                          qo_fields => 'fullrecord',          if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
129                          citedref => 'citedref',                  warn "W: no ra_name\n";
130                    return;
131                          save_options => 'plain_text',          }
132            warn "# refine years (hidden by javascript)";
133                          fields => 'Full',          warn "http://apps.isiknowledge.com/RAMore.do?product=WOS&search_mode=TotalCitingArticles&SID=T1o6bChdN9PGP1LN1Nh&qid=3&ra_mode=more&ra_name=PublicationYear&db_id=WOS&viewType=raMore\n$years_url\n";
134                          format => 'save',          $mech->get( $years_url );
                 },  
                 button => 'save',  
         );  
135          save_mech $mech;          save_mech $mech;
136    
137          last if $mech->content =~ m{invalid API call};          my $html = $mech->content;
138            my $years;
139            while ( $html =~ s{>(\d\d\d\d)\s\((\d+)\)</label.+?value="PublicationYear_}{} ) {
140                    $years->{$1} = $2;
141            }
142            warn "# years ",dump $years;
143            $mech->back;
144            return $years;
145    }
146    
147          warn "# save_file";  search;
148          $mech->follow_link( url_regex => qr/save_file/ );  years;
149          save_mech $mech => "/tmp/isi.$q.$from-$to.txt";  get_results;
150    
         $from += $range_size;  
151    
152          $mech->back;  citations;
153          $mech->back;  years;
154          #save_mech $mech;  $q .= '.citing';
155    get_results;
156    
 }  

Legend:
Removed from v.1282  
changed lines
  Added in v.1291

  ViewVC Help
Powered by ViewVC 1.1.26