/[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 1334 by dpavlin, Fri Jun 4 17:43:29 2010 UTC revision 1369 by dpavlin, Wed Aug 8 14:20:26 2012 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  my $range_size = 500;  $q = 'AU=BRATKO, D';
16    #$q = 'AD=(croat* OR hrvat*)';
17    
18    my $range_size = 100;
19  my $overlap    = 3; # between previous and this range  my $overlap    = 3; # between previous and this range
20  my $results = 0;  
21    my $results = 1;
22  my $citations = 0;  my $citations = 0;
23    my $cited_reference = 0; # html tables
24    my $citing_articles = 0; # as many files as cited articles
25    
26  my $cites_by_year = 0;  my $cites_by_year = 0;
27    
28  my $max_cites = 5000; # ISI limit to get cites  my $max_cites = 5000; # ISI limit to get cites
29    
 if ( 0 ) {  
         $q = 'TS=psychology AND AD=Croatia';  
         $range_size = 50;  
         $overlap    = 0;  
         $max_cites  = 50;  
 }  
   
30  $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;  $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;
31    
32    warn "QUERY: $q\n";
33    
34  our $mech = WWW::Mechanize->new(  our $mech = WWW::Mechanize->new(
35          autocheck => 0, # it dies in reference download with it!          autocheck => 0, # it dies in reference download with it!
36          cookie_jar => undef,          cookie_jar => undef,
# Line 54  sub save_mech { Line 56  sub save_mech {
56  }  }
57    
58  warn "# get session";  warn "# get session";
59  $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );  $mech->get( 'http://www.webofknowledge.com/?DestApp=WOS' );
60  save_mech;  save_mech;
61    
62  sub search {  sub search {
# Line 92  sub get_results { Line 94  sub get_results {
94                  my $to = $from + $range_size;                  my $to = $from + $range_size;
95    
96                  warn "# submit_form results $from - $to\n";                  warn "# submit_form results $from - $to\n";
97                    save_mech;
98    
99                  $mech->submit_form(                  $mech->submit_form(
100                          form_name => 'summary_output_form',                          form_name => 'output_form',
101                          fields => {                          fields => {
102                                  record_select_type => 'range',                                  'value(record_select_type)' => 'range',
103                                    markFrom => $from,
104                                    markTo => $to,
105    
106                                  mark_from => $from,                                  mark_from => $from,
107                                  mark_to => $to,                                  mark_to => $to,
108                                  mark_id => 'WOS',                                  mark_id => 'WOS',
109    
110                                  qo_fields => 'fullrecord',                                  fields_selection => 'ACCESSION_NUM FUNDING SUBJECT_CATEGORY JCR_CATEGORY LANG IDS PAGEC SABBR CITREFC ISSN PUBINFO KEYWORDS CITTIMES ADDRS CONFERENCE_SPONSORS DOCTYPE ABSTRACT CONFERENCE_INFO SOURCE TITLE AUTHORS',
111                                  citedref => 'citedref',                                  filters => 'ACCESSION_NUM FUNDING SUBJECT_CATEGORY JCR_CATEGORY LANG IDS PAGEC SABBR CITREFC ISSN PUBINFO KEYWORDS CITTIMES ADDRS CONFERENCE_SPONSORS DOCTYPE ABSTRACT CONFERENCE_INFO SOURCE TITLE AUTHORS CITREF',
112                                    fullrec_fields_option => 'CITREF',
113    
114                                  save_options => 'plain_text',                                  save_options => 'fieldtagged',
115                                    format => 'saveToFile',
116    
                                 fields => 'Full',  
                                 format => 'save',  
117                          },                          },
118                          button => 'save',                          button => 'saveToFile',
119                  );                  );
120                  save_mech;                  save_mech;
121    
# Line 119  sub get_results { Line 125  sub get_results {
125                          last;                          last;
126                  }                  }
127    
128                    if ( $mech->content !~ m{Please wait while your request is processed} ) {
129                            warn "WARNING: expecting processing request";
130                    }
131    
132    
133                  my $path = "/tmp/isi.$q.$from-$to";                  my $path = "/tmp/isi.$q.$from-$to";
134                  $path .= '.' . $desc if $desc;                  $path .= '.' . $desc if $desc;
135    
136                  warn "save $from - $to into $path\n";                  warn "save $from - $to into $path\n";
137                  $mech->follow_link( url_regex => qr/save_file/ );                  $mech->submit_form(
138                            form_name => 'etsForm',
139                    );
140                  save_mech $path;                  save_mech $path;
141    
142                  $from += $range_size - $overlap;                  $from += $range_size - $overlap;
143    
144                  $mech->back;                  $mech->back;
145                  $mech->back;                  $mech->back;
146                  #save_mech;                  save_mech;
147          }          }
148  }  }
149    
# Line 212  sub years { Line 224  sub years {
224          return $years;          return $years;
225  }  }
226    
227  search;  
228  years;  our $page = 1;
229  get_results 'results' if $results;  sub next_page {
230            $page++;
231            warn "next_page $page\n";
232    
233            $mech->submit_form(
234                    form_name => 'summary_navigation',
235                    fields => {
236                            'page' => $page,
237                    },
238            );
239    
240            save_mech;
241    
242            $mech->form_name( 'summary_navigation' );
243            my $is_next_page = $mech->value('page') == $page;
244            warn "no next_page" unless $is_next_page;
245            return $is_next_page;
246    }
247    
248    if ( $results ) {
249            search;
250            years;
251            get_results;
252    }
253    
254  if ( $citations ) {  if ( $citations ) {
255    
256          citations;          citations;
257            years unless @ranges;
258    
259          do {          do {
260                  my $part;                  my $part;
# Line 232  if ( $citations ) { Line 268  if ( $citations ) {
268          } while ( @ranges );          } while ( @ranges );
269    
270  }  }
271    
272    
273    
274    if ( $q =~ m{CA=(.+)} && $cited_reference ) {
275    
276            my $CA = $1;
277    
278            warn "# citated reference search";
279            $mech->follow_link( url_regex => qr/CitedReferenceSearch/ );
280            save_mech;
281    
282    
283            $mech->submit_form(
284                    form_name => 'WOS_CitedReferenceSearch_input_form',
285                    fields => {
286                            'value(input1)' => $CA,
287                    },
288            );
289    
290            my $page = 1;
291            my $records = $1 if $mech->content =~ m/(\d+)\s+records/;
292            warn "# found $records records\n";
293            my $last_span = 'fake';
294    
295            while (1) {
296                    save_mech "/tmp/isi.$q.citedref.$page";
297    
298                    last unless next_page();
299    
300                    if ( $mech->content =~ m/(\d+\s*-\s*(\d+))/ ) {
301                            warn "span: $1\n";
302                            last if $2 == $records;
303                            last if $1 == $last_span;
304                            $last_span = $1;
305                    } elsif ( $page > 5 ) {
306                            warn "ARTIFICALLY LIMITED TO 5 PAGES WITHOUT VALID SPAN!";
307                            last;
308                    }
309    
310            }
311    
312    }
313    
314    if ( $q =~ m{CA=(.+)} && $citing_articles ) {
315    
316            search;
317    
318            my $orig_q = $q;
319            my $nr = 0;
320    
321            do {
322    
323            foreach my $link ( $mech->find_all_links( url_regex => qr/CitingArticles.do/ ) ) {
324                    $nr++;
325                    warn "link $nr\n";
326                    $mech->get( $link->url );
327                    save_mech;
328                    $q = $orig_q . '.citing_article.' . $nr;
329                    get_results;
330                    $mech->back;
331                    $mech->back;
332    
333                    #last if $nr > 3; # FIXME only for development
334            }
335    
336            } while next_page;
337    
338            $q = $orig_q;
339    }
340    
341    warn "OVER\n";

Legend:
Removed from v.1334  
changed lines
  Added in v.1369

  ViewVC Help
Powered by ViewVC 1.1.26