3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
|
use WWW::Mechanize; |
7 |
|
use Data::Dump qw(dump); |
8 |
|
use File::Path; |
9 |
|
use Text::Unaccent; |
10 |
|
|
11 |
# Advanced search syntax: |
# Advanced search syntax: |
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 $skip_results = 1; |
|
21 |
|
my $results = 1; |
22 |
|
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; |
27 |
|
|
28 |
my $max_cites = 5000; # ISI limit to get cites |
my $max_cites = 5000; # ISI limit to get cites |
29 |
|
|
30 |
if ( 0 ) { |
$q = unac_string( 'utf-8', join(' ', @ARGV) ) if @ARGV; |
|
$q = 'TS=psychology AND AD=Croatia'; |
|
|
$range_size = 50; |
|
|
$overlap = 0; |
|
|
$max_cites = 50; |
|
|
} |
|
31 |
|
|
32 |
use WWW::Mechanize; |
warn "QUERY: $q\n"; |
|
use Data::Dump qw(dump); |
|
|
use File::Path; |
|
33 |
|
|
34 |
our $mech = WWW::Mechanize->new( |
our $mech = WWW::Mechanize->new( |
35 |
autocheck => 1, |
autocheck => 0, # it dies in reference download with it! |
36 |
cookie_jar => undef, |
cookie_jar => undef, |
37 |
); |
); |
38 |
|
|
40 |
our @ranges; |
our @ranges; |
41 |
|
|
42 |
my $dir = '/tmp/isi/'; |
my $dir = '/tmp/isi/'; |
43 |
rmtree $dir if -e $dir; |
#rmtree $dir if -e $dir; |
44 |
mkdir $dir; |
mkdir $dir unless -d $dir; |
45 |
|
|
46 |
sub save_mech { |
sub save_mech { |
47 |
my $path = shift; |
my $path = shift; |
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 { |
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 |
|
|
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 |
|
|
187 |
|
|
188 |
my @y = sort keys %$years; |
my @y = sort keys %$years; |
189 |
|
|
190 |
|
@ranges = (); |
191 |
|
|
192 |
|
if ( $cites_by_year ) { |
193 |
|
push @ranges, [ $_ ] foreach @y; |
194 |
|
warn "# cites_by_year ranges ", dump @ranges; |
195 |
|
return; |
196 |
|
} |
197 |
|
|
198 |
my $y = shift @y; |
my $y = shift @y; |
199 |
my $size = $years->{$y}; |
my $size = $years->{$y}; |
200 |
|
|
|
@ranges = (); |
|
201 |
my $cites_range; |
my $cites_range; |
202 |
$cites_range = [$y] if $y; |
$cites_range = [$y] if $y; |
203 |
|
|
224 |
return $years; |
return $years; |
225 |
} |
} |
226 |
|
|
|
search; |
|
|
years; |
|
|
get_results unless $skip_results; |
|
227 |
|
|
228 |
|
our $page = 1; |
229 |
|
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 |
citations; |
if ( $citations ) { |
255 |
|
|
256 |
do { |
citations; |
257 |
my $part; |
years unless @ranges; |
258 |
if ( @ranges ) { |
|
259 |
$part .= $ranges[0]->[0] . '.'; |
do { |
260 |
search; |
my $part; |
261 |
citations; |
if ( @ranges ) { |
262 |
} |
$part .= $ranges[0]->[0] . '.'; |
263 |
$part .= 'citing'; |
search; |
264 |
get_results $part; |
citations; |
265 |
} while ( @ranges ); |
} |
266 |
|
$part .= 'citing'; |
267 |
|
get_results $part; |
268 |
|
} 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"; |