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
19 my $cites_by_year = 0;
21 my $max_cites = 5000; # ISI limit to get cites
24 $q = 'TS=psychology AND AD=Croatia';
30 $q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV;
32 our $mech = WWW::Mechanize->new(
33 autocheck => 0, # it dies in reference download with it!
40 my $dir = '/tmp/isi/';
41 #rmtree $dir if -e $dir;
42 mkdir $dir unless -d $dir;
47 my $base_path = sprintf('%s/%04d', $dir,$step);
49 $path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt';
50 $mech->save_content( $path );
51 warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
52 open(my $dump, '>', "$base_path.dump.txt");
53 $mech->dump_all($dump);
57 $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
61 warn "# advanced serach";
62 $mech->follow_link( url_regex => qr/AdvancedSearch/ );
65 warn "# cookie_jar ", dump $mech->cookie_jar;
70 $q_this .= ' AND (' . join(' OR ', map { "PY=$_" } @{ shift @ranges } ) . ')';
73 warn "# submit_form search: $q_this\n";
76 'value(input1)' => $q_this,
82 $mech->follow_link( url_regex => qr/summary/ );
92 my $to = $from + $range_size;
94 warn "# submit_form results $from - $to\n";
97 form_name => 'summary_output_form',
99 record_select_type => 'range',
104 qo_fields => 'fullrecord',
105 citedref => 'citedref',
107 save_options => 'plain_text',
117 if ( $mech->content =~ m{invalid API call} ) {
123 my $path = "/tmp/isi.$q.$from-$to";
124 $path .= '.' . $desc if $desc;
126 warn "save $from - $to into $path\n";
127 $mech->follow_link( url_regex => qr/save_file/ );
130 $from += $range_size - $overlap;
140 warn "# citation report";
141 $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
144 warn "view citing articles";
145 $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
150 my $years_url = $mech->find_link( url_regex => qr/ra_name=/ );
151 if ( ! $years_url ) {
152 warn "W: can't find ra_name link\n";
155 $years_url = $years_url->url_abs;
156 warn "## $years_url";
157 if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
158 warn "W: no ra_name in $years_url\n";
161 warn "# refine years (hidden by javascript)";
162 # 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";
163 $mech->get( $years_url );
166 my $html = $mech->content;
168 while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) {
169 my ( $year, $count ) = ( $1, $2 );
171 $years->{$year} = $count;
173 warn "# years ",dump $years;
176 my @y = sort keys %$years;
180 if ( $cites_by_year ) {
181 push @ranges, [ $_ ] foreach @y;
182 warn "# cites_by_year ranges ", dump @ranges;
187 my $size = $years->{$y};
190 $cites_range = [$y] if $y;
192 foreach my $y ( @y ) {
193 if ( $size + $years->{$y} > $max_cites ) {
194 push @ranges, $cites_range;
195 warn "# cites_range $size years ",dump( $cites_range ),$/;
200 $size += $years->{$y};
201 push @$cites_range, $y;
204 if ( $cites_range ) {
205 push @ranges, $cites_range;
206 warn "# cites_range $size years ",dump( $cites_range ), " FINAL\n"
209 warn '# ranges ', dump @ranges;
210 @ranges = () if $#ranges == 1; # just take all
217 get_results 'results' if $results;
226 $part .= $ranges[0]->[0] . '.';