3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
|
# Advanced search syntax: |
7 |
|
# http://images.isiknowledge.com/WOK46/help/WOS/h_advanced_examples.html |
8 |
|
|
9 |
our $q = 'AD=Croatia'; |
our $q = 'AD=Croatia'; |
10 |
my $range_size = 500; |
my $range_size = 500; |
11 |
|
my $overlap = 3; # between previous and this range |
12 |
|
my $skip_results = 1; |
13 |
|
|
14 |
my $dump = @ARGV ? 1 : 0; |
my $max_cites = 5000; # ISI limit to get cites |
15 |
|
|
16 |
$q = 'TS=psychology AND AD=Croatia'; |
if ( 0 ) { |
17 |
|
$q = 'TS=psychology AND AD=Croatia'; |
18 |
|
$range_size = 50; |
19 |
|
$overlap = 0; |
20 |
|
$max_cites = 50; |
21 |
|
} |
22 |
|
|
23 |
use WWW::Mechanize; |
use WWW::Mechanize; |
24 |
use Data::Dump qw(dump); |
use Data::Dump qw(dump); |
30 |
); |
); |
31 |
|
|
32 |
our $step = 0; |
our $step = 0; |
33 |
|
our @ranges; |
34 |
|
|
35 |
my $dir = '/tmp/isi/'; |
my $dir = '/tmp/isi/'; |
36 |
rmtree $dir if -e $dir; |
rmtree $dir if -e $dir; |
37 |
mkdir $dir; |
mkdir $dir; |
38 |
|
|
39 |
sub save_mech { |
sub save_mech { |
40 |
my ( $mech, $path ) = @_; |
my $path = shift; |
41 |
$step++; |
$step++; |
42 |
my $base_path = sprintf('%s/%04d', $dir,$step); |
my $base_path = sprintf('%s/%04d', $dir,$step); |
43 |
$path ||= $base_path . ( $mech->{ct} =~ m{html}i ? '.html' : '.txt' ); |
$path ||= $base_path; |
44 |
|
$path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt'; |
45 |
$mech->save_content( $path ); |
$mech->save_content( $path ); |
46 |
warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n"; |
warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n"; |
47 |
open(my $dump, '>', "$base_path.dump.txt"); |
open(my $dump, '>', "$base_path.dump.txt"); |
50 |
|
|
51 |
warn "# get session"; |
warn "# get session"; |
52 |
$mech->get( 'http://isiknowledge.com/?DestApp=WOS' ); |
$mech->get( 'http://isiknowledge.com/?DestApp=WOS' ); |
53 |
save_mech $mech; |
save_mech; |
54 |
|
|
55 |
sub search { |
sub search { |
56 |
warn "# advanced serach"; |
warn "# advanced serach"; |
57 |
$mech->follow_link( url_regex => qr/AdvancedSearch/ ); |
$mech->follow_link( url_regex => qr/AdvancedSearch/ ); |
58 |
save_mech $mech; |
save_mech; |
59 |
|
|
60 |
warn "# cookie_jar ", dump $mech->cookie_jar; |
warn "# cookie_jar ", dump $mech->cookie_jar; |
61 |
|
|
62 |
|
my $q_this = $q; |
63 |
|
|
64 |
|
if ( @ranges ) { |
65 |
|
$q_this .= ' AND (' . join(' OR ', map { "PY=$_" } @{ shift @ranges } ) . ')'; |
66 |
|
} |
67 |
|
|
68 |
|
warn "# submit_form search: $q_this\n"; |
69 |
$mech->submit_form( |
$mech->submit_form( |
70 |
fields => { |
fields => { |
71 |
'value(input1)' => $q, |
'value(input1)' => $q_this, |
72 |
} |
}, |
73 |
); |
); |
74 |
save_mech $mech; |
save_mech; |
75 |
|
|
76 |
warn "# summary"; |
warn "# summary"; |
77 |
$mech->follow_link( url_regex => qr/summary/ ); |
$mech->follow_link( url_regex => qr/summary/ ); |
78 |
save_mech $mech; |
save_mech; |
79 |
} |
} |
80 |
|
|
81 |
sub get_results { |
sub get_results { |
82 |
|
my $desc = shift; |
83 |
my $from = 1; |
my $from = 1; |
84 |
|
|
85 |
while ( 1 ) { |
while ( 1 ) { |
86 |
|
|
87 |
my $to = $from + $range_size; |
my $to = $from + $range_size; |
88 |
|
|
89 |
|
warn "# submit_form results $from - $to\n"; |
90 |
|
|
91 |
$mech->submit_form( |
$mech->submit_form( |
92 |
form_name => 'summary_output_form', |
form_name => 'summary_output_form', |
93 |
fields => { |
fields => { |
106 |
}, |
}, |
107 |
button => 'save', |
button => 'save', |
108 |
); |
); |
109 |
save_mech $mech; |
save_mech; |
110 |
|
|
111 |
|
|
112 |
if ( $mech->content =~ m{invalid API call} ) { |
if ( $mech->content =~ m{invalid API call} ) { |
113 |
$mech->back; |
$mech->back; |
114 |
last; |
last; |
115 |
} |
} |
116 |
|
|
117 |
warn "range $from - $to [$q]\n"; |
|
118 |
|
my $path = "/tmp/isi.$q.$from-$to"; |
119 |
|
$path .= '.' . $desc if $desc; |
120 |
|
|
121 |
|
warn "save $from - $to into $path\n"; |
122 |
$mech->follow_link( url_regex => qr/save_file/ ); |
$mech->follow_link( url_regex => qr/save_file/ ); |
123 |
save_mech $mech => "/tmp/isi.$q.$from-$to.txt"; |
save_mech $path; |
124 |
|
|
125 |
$from += $range_size; |
$from += $range_size - $overlap; |
126 |
|
|
127 |
$mech->back; |
$mech->back; |
128 |
$mech->back; |
$mech->back; |
129 |
#save_mech $mech; |
#save_mech; |
|
|
|
130 |
} |
} |
|
|
|
131 |
} |
} |
132 |
|
|
133 |
|
|
134 |
sub citations { |
sub citations { |
|
save_mech $mech; |
|
135 |
warn "# citation report"; |
warn "# citation report"; |
136 |
$mech->follow_link( url_regex => qr/search_mode=CitationReport/ ); |
$mech->follow_link( url_regex => qr/search_mode=CitationReport/ ); |
137 |
save_mech $mech; |
save_mech; |
138 |
|
|
139 |
warn "view citing articles"; |
warn "view citing articles"; |
140 |
$mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ ); |
$mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ ); |
141 |
save_mech $mech; |
save_mech; |
142 |
} |
} |
143 |
|
|
144 |
sub years { |
sub years { |
145 |
my $years_url = $mech->find_link( text_regex => qr/more options/ ); |
my $years_url = $mech->find_link( url_regex => qr/ra_name=/ ); |
146 |
if ( ! $years_url ) { |
if ( ! $years_url ) { |
147 |
warn "W: can't find years\n"; |
warn "W: can't find ra_name link\n"; |
148 |
return; |
return; |
149 |
} |
} |
150 |
$years_url = $years_url->url_abs; |
$years_url = $years_url->url_abs; |
151 |
warn "## $years_url"; |
warn "## $years_url"; |
152 |
if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) { |
if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) { |
153 |
warn "W: no ra_name\n"; |
warn "W: no ra_name in $years_url\n"; |
154 |
return; |
return; |
155 |
} |
} |
156 |
warn "# refine years (hidden by javascript)"; |
warn "# refine years (hidden by javascript)"; |
157 |
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"; |
# 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"; |
158 |
$mech->get( $years_url ); |
$mech->get( $years_url ); |
159 |
save_mech $mech; |
save_mech; |
160 |
|
|
161 |
my $html = $mech->content; |
my $html = $mech->content; |
162 |
my $years; |
my $years; |
163 |
while ( $html =~ s{>(\d\d\d\d)\s\((\d+)\)</label.+?value="PublicationYear_}{} ) { |
while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) { |
164 |
$years->{$1} = $2; |
my ( $year, $count ) = ( $1, $2 ); |
165 |
|
$count =~ s{,}{}g; |
166 |
|
$years->{$year} = $count; |
167 |
} |
} |
168 |
warn "# years ",dump $years; |
warn "# years ",dump $years; |
169 |
$mech->back; |
$mech->back; |
170 |
|
|
171 |
|
my @y = sort keys %$years; |
172 |
|
|
173 |
|
my $y = shift @y; |
174 |
|
my $size = $years->{$y}; |
175 |
|
|
176 |
|
@ranges = (); |
177 |
|
my $cites_range; |
178 |
|
$cites_range = [$y] if $y; |
179 |
|
|
180 |
|
foreach my $y ( @y ) { |
181 |
|
if ( $size + $years->{$y} > $max_cites ) { |
182 |
|
push @ranges, $cites_range; |
183 |
|
warn "# cites_range $size years ",dump( $cites_range ),$/; |
184 |
|
|
185 |
|
$cites_range = []; |
186 |
|
$size = 0; |
187 |
|
} |
188 |
|
$size += $years->{$y}; |
189 |
|
push @$cites_range, $y; |
190 |
|
} |
191 |
|
|
192 |
|
if ( $cites_range ) { |
193 |
|
push @ranges, $cites_range; |
194 |
|
warn "# cites_range $size years ",dump( $cites_range ), " FINAL\n" |
195 |
|
} |
196 |
|
|
197 |
|
warn '# ranges ', dump @ranges; |
198 |
|
@ranges = () if $#ranges == 1; # just take all |
199 |
|
|
200 |
return $years; |
return $years; |
201 |
} |
} |
202 |
|
|
203 |
search; |
search; |
204 |
years; |
years; |
205 |
get_results; |
get_results unless $skip_results; |
206 |
|
|
207 |
|
|
208 |
citations; |
citations; |
209 |
years; |
|
210 |
$q .= '.citing'; |
do { |
211 |
get_results; |
my $part; |
212 |
|
if ( @ranges ) { |
213 |
|
$part .= $ranges[0]->[0] . '.'; |
214 |
|
search; |
215 |
|
citations; |
216 |
|
} |
217 |
|
$part .= 'citing'; |
218 |
|
get_results $part; |
219 |
|
} while ( @ranges ); |
220 |
|
|