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';
24 $q = join(' ', @ARGV) if @ARGV;
27 use Data::Dump qw(dump);
30 our $mech = WWW::Mechanize->new(
38 my $dir = '/tmp/isi/';
39 #rmtree $dir if -e $dir;
40 mkdir $dir unless -d $dir;
45 my $base_path = sprintf('%s/%04d', $dir,$step);
47 $path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt';
48 $mech->save_content( $path );
49 warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
50 open(my $dump, '>', "$base_path.dump.txt");
51 $mech->dump_all($dump);
55 $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
59 warn "# advanced serach";
60 $mech->follow_link( url_regex => qr/AdvancedSearch/ );
63 warn "# cookie_jar ", dump $mech->cookie_jar;
68 $q_this .= ' AND (' . join(' OR ', map { "PY=$_" } @{ shift @ranges } ) . ')';
71 warn "# submit_form search: $q_this\n";
74 'value(input1)' => $q_this,
80 $mech->follow_link( url_regex => qr/summary/ );
90 my $to = $from + $range_size;
92 warn "# submit_form results $from - $to\n";
95 form_name => 'summary_output_form',
97 record_select_type => 'range',
102 qo_fields => 'fullrecord',
103 citedref => 'citedref',
105 save_options => 'plain_text',
115 if ( $mech->content =~ m{invalid API call} ) {
121 my $path = "/tmp/isi.$q.$from-$to";
122 $path .= '.' . $desc if $desc;
124 warn "save $from - $to into $path\n";
125 $mech->follow_link( url_regex => qr/save_file/ );
128 $from += $range_size - $overlap;
138 warn "# citation report";
139 $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
142 warn "view citing articles";
143 $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
148 my $years_url = $mech->find_link( url_regex => qr/ra_name=/ );
149 if ( ! $years_url ) {
150 warn "W: can't find ra_name link\n";
153 $years_url = $years_url->url_abs;
154 warn "## $years_url";
155 if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
156 warn "W: no ra_name in $years_url\n";
159 warn "# refine years (hidden by javascript)";
160 # 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";
161 $mech->get( $years_url );
164 my $html = $mech->content;
166 while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) {
167 my ( $year, $count ) = ( $1, $2 );
169 $years->{$year} = $count;
171 warn "# years ",dump $years;
174 my @y = sort keys %$years;
178 if ( $cites_by_year ) {
179 push @ranges, [ $_ ] foreach @y;
180 warn "# cites_by_year ranges ", dump @ranges;
185 my $size = $years->{$y};
188 $cites_range = [$y] if $y;
190 foreach my $y ( @y ) {
191 if ( $size + $years->{$y} > $max_cites ) {
192 push @ranges, $cites_range;
193 warn "# cites_range $size years ",dump( $cites_range ),$/;
198 $size += $years->{$y};
199 push @$cites_range, $y;
202 if ( $cites_range ) {
203 push @ranges, $cites_range;
204 warn "# cites_range $size years ",dump( $cites_range ), " FINAL\n"
207 warn '# ranges ', dump @ranges;
208 @ranges = () if $#ranges == 1; # just take all
215 get_results unless $skip_results;
223 $part .= $ranges[0]->[0] . '.';