6 # Advanced search syntax:
7 # http://images.isiknowledge.com/WOK46/help/WOS/h_advanced_examples.html
11 my $overlap = 3; # between previous and this range
13 my $cites_by_year = 1;
15 my $max_cites = 5000; # ISI limit to get cites
18 $q = 'TS=psychology AND AD=Croatia';
25 use Data::Dump qw(dump);
28 our $mech = WWW::Mechanize->new(
36 my $dir = '/tmp/isi/';
37 rmtree $dir if -e $dir;
43 my $base_path = sprintf('%s/%04d', $dir,$step);
45 $path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt';
46 $mech->save_content( $path );
47 warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
48 open(my $dump, '>', "$base_path.dump.txt");
49 $mech->dump_all($dump);
53 $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
57 warn "# advanced serach";
58 $mech->follow_link( url_regex => qr/AdvancedSearch/ );
61 warn "# cookie_jar ", dump $mech->cookie_jar;
66 $q_this .= ' AND (' . join(' OR ', map { "PY=$_" } @{ shift @ranges } ) . ')';
69 warn "# submit_form search: $q_this\n";
72 'value(input1)' => $q_this,
78 $mech->follow_link( url_regex => qr/summary/ );
88 my $to = $from + $range_size;
90 warn "# submit_form results $from - $to\n";
93 form_name => 'summary_output_form',
95 record_select_type => 'range',
100 qo_fields => 'fullrecord',
101 citedref => 'citedref',
103 save_options => 'plain_text',
113 if ( $mech->content =~ m{invalid API call} ) {
119 my $path = "/tmp/isi.$q.$from-$to";
120 $path .= '.' . $desc if $desc;
122 warn "save $from - $to into $path\n";
123 $mech->follow_link( url_regex => qr/save_file/ );
126 $from += $range_size - $overlap;
136 warn "# citation report";
137 $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
140 warn "view citing articles";
141 $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
146 my $years_url = $mech->find_link( url_regex => qr/ra_name=/ );
147 if ( ! $years_url ) {
148 warn "W: can't find ra_name link\n";
151 $years_url = $years_url->url_abs;
152 warn "## $years_url";
153 if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
154 warn "W: no ra_name in $years_url\n";
157 warn "# refine years (hidden by javascript)";
158 # 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";
159 $mech->get( $years_url );
162 my $html = $mech->content;
164 while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) {
165 my ( $year, $count ) = ( $1, $2 );
167 $years->{$year} = $count;
169 warn "# years ",dump $years;
172 my @y = sort keys %$years;
176 if ( $cites_by_year ) {
177 push @ranges, [ $_ ] foreach @y;
178 warn "# cites_by_year ranges ", dump @ranges;
183 my $size = $years->{$y};
186 $cites_range = [$y] if $y;
188 foreach my $y ( @y ) {
189 if ( $size + $years->{$y} > $max_cites ) {
190 push @ranges, $cites_range;
191 warn "# cites_range $size years ",dump( $cites_range ),$/;
196 $size += $years->{$y};
197 push @$cites_range, $y;
200 if ( $cites_range ) {
201 push @ranges, $cites_range;
202 warn "# cites_range $size years ",dump( $cites_range ), " FINAL\n"
205 warn '# ranges ', dump @ranges;
206 @ranges = () if $#ranges == 1; # just take all
213 get_results unless $skip_results;
221 $part .= $ranges[0]->[0] . '.';