7 use Data::Dump qw(dump);
11 # Advanced search syntax:
12 # http://images.isiknowledge.com/WOK46/help/WOS/h_advanced_examples.html
14 our $q = 'AD=Croatia';
16 my $overlap = 3; # between previous and this range
18 my $cites_by_year = 0;
20 my $max_cites = 5000; # ISI limit to get cites
23 $q = 'TS=psychology AND AD=Croatia';
29 $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;
31 our $mech = WWW::Mechanize->new(
39 my $dir = '/tmp/isi/';
40 #rmtree $dir if -e $dir;
41 mkdir $dir unless -d $dir;
46 my $base_path = sprintf('%s/%04d', $dir,$step);
48 $path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt';
49 $mech->save_content( $path );
50 warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
51 open(my $dump, '>', "$base_path.dump.txt");
52 $mech->dump_all($dump);
56 $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
60 warn "# advanced serach";
61 $mech->follow_link( url_regex => qr/AdvancedSearch/ );
64 warn "# cookie_jar ", dump $mech->cookie_jar;
69 $q_this .= ' AND (' . join(' OR ', map { "PY=$_" } @{ shift @ranges } ) . ')';
72 warn "# submit_form search: $q_this\n";
75 'value(input1)' => $q_this,
81 $mech->follow_link( url_regex => qr/summary/ );
91 my $to = $from + $range_size;
93 warn "# submit_form results $from - $to\n";
96 form_name => 'summary_output_form',
98 record_select_type => 'range',
103 qo_fields => 'fullrecord',
104 citedref => 'citedref',
106 save_options => 'plain_text',
116 if ( $mech->content =~ m{invalid API call} ) {
122 my $path = "/tmp/isi.$q.$from-$to";
123 $path .= '.' . $desc if $desc;
125 warn "save $from - $to into $path\n";
126 $mech->follow_link( url_regex => qr/save_file/ );
129 $from += $range_size - $overlap;
139 warn "# citation report";
140 $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
143 warn "view citing articles";
144 $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
149 my $years_url = $mech->find_link( url_regex => qr/ra_name=/ );
150 if ( ! $years_url ) {
151 warn "W: can't find ra_name link\n";
154 $years_url = $years_url->url_abs;
155 warn "## $years_url";
156 if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
157 warn "W: no ra_name in $years_url\n";
160 warn "# refine years (hidden by javascript)";
161 # 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";
162 $mech->get( $years_url );
165 my $html = $mech->content;
167 while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) {
168 my ( $year, $count ) = ( $1, $2 );
170 $years->{$year} = $count;
172 warn "# years ",dump $years;
175 my @y = sort keys %$years;
179 if ( $cites_by_year ) {
180 push @ranges, [ $_ ] foreach @y;
181 warn "# cites_by_year ranges ", dump @ranges;
186 my $size = $years->{$y};
189 $cites_range = [$y] if $y;
191 foreach my $y ( @y ) {
192 if ( $size + $years->{$y} > $max_cites ) {
193 push @ranges, $cites_range;
194 warn "# cites_range $size years ",dump( $cites_range ),$/;
199 $size += $years->{$y};
200 push @$cites_range, $y;
203 if ( $cites_range ) {
204 push @ranges, $cites_range;
205 warn "# cites_range $size years ",dump( $cites_range ), " FINAL\n"
208 warn '# ranges ', dump @ranges;
209 @ranges = () if $#ranges == 1; # just take all
216 get_results unless $skip_results;
224 $part .= $ranges[0]->[0] . '.';