/[webpac2]/trunk/bin/isi-download-results.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/isi-download-results.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1299 - (show annotations)
Sat Sep 19 23:37:55 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 4380 byte(s)
$skip_results to get just citations
1 #!/usr/bin/perl
2
3 use warnings;
4 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';
10 my $range_size = 500;
11 my $overlap = 3; # between previous and this range
12 my $skip_results = 1;
13
14 my $max_cites = 5000; # ISI limit to get cites
15
16 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;
24 use Data::Dump qw(dump);
25 use File::Path;
26
27 our $mech = WWW::Mechanize->new(
28 autocheck => 1,
29 cookie_jar => undef,
30 );
31
32 our $step = 0;
33 our @ranges;
34
35 my $dir = '/tmp/isi/';
36 rmtree $dir if -e $dir;
37 mkdir $dir;
38
39 sub save_mech {
40 my $path = shift;
41 $step++;
42 my $base_path = sprintf('%s/%04d', $dir,$step);
43 $path ||= $base_path;
44 $path .= $mech->{ct} =~ m{html}i ? '.html' : '.txt';
45 $mech->save_content( $path );
46 warn "# [$step] $path ", -s $path, " ", $mech->ct, "\n";
47 open(my $dump, '>', "$base_path.dump.txt");
48 $mech->dump_all($dump);
49 }
50
51 warn "# get session";
52 $mech->get( 'http://isiknowledge.com/?DestApp=WOS' );
53 save_mech;
54
55 sub search {
56 warn "# advanced serach";
57 $mech->follow_link( url_regex => qr/AdvancedSearch/ );
58 save_mech;
59
60 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(
70 fields => {
71 'value(input1)' => $q_this,
72 },
73 );
74 save_mech;
75
76 warn "# summary";
77 $mech->follow_link( url_regex => qr/summary/ );
78 save_mech;
79 }
80
81 sub get_results {
82 my $desc = shift;
83 my $from = 1;
84
85 while ( 1 ) {
86
87 my $to = $from + $range_size;
88
89 warn "# submit_form results $from - $to\n";
90
91 $mech->submit_form(
92 form_name => 'summary_output_form',
93 fields => {
94 record_select_type => 'range',
95 mark_from => $from,
96 mark_to => $to,
97 mark_id => 'WOS',
98
99 qo_fields => 'fullrecord',
100 citedref => 'citedref',
101
102 save_options => 'plain_text',
103
104 fields => 'Full',
105 format => 'save',
106 },
107 button => 'save',
108 );
109 save_mech;
110
111
112 if ( $mech->content =~ m{invalid API call} ) {
113 $mech->back;
114 last;
115 }
116
117
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/ );
123 save_mech $path;
124
125 $from += $range_size - $overlap;
126
127 $mech->back;
128 $mech->back;
129 #save_mech;
130 }
131 }
132
133
134 sub citations {
135 warn "# citation report";
136 $mech->follow_link( url_regex => qr/search_mode=CitationReport/ );
137 save_mech;
138
139 warn "view citing articles";
140 $mech->follow_link( url_regex => qr/search_mode=TotalCitingArticles/ );
141 save_mech;
142 }
143
144 sub years {
145 my $years_url = $mech->find_link( url_regex => qr/ra_name=/ );
146 if ( ! $years_url ) {
147 warn "W: can't find ra_name link\n";
148 return;
149 }
150 $years_url = $years_url->url_abs;
151 warn "## $years_url";
152 if ( $years_url !~ s{ra_name=\w+}{ra_name=PublicationYear} ) {
153 warn "W: no ra_name in $years_url\n";
154 return;
155 }
156 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";
158 $mech->get( $years_url );
159 save_mech;
160
161 my $html = $mech->content;
162 my $years;
163 while ( $html =~ s{<label.+?PublicationYear.+?>(\d{4})\s\(([\d,]+)\)</label>}{} ) {
164 my ( $year, $count ) = ( $1, $2 );
165 $count =~ s{,}{}g;
166 $years->{$year} = $count;
167 }
168 warn "# years ",dump $years;
169 $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;
201 }
202
203 search;
204 years;
205 get_results unless $skip_results;
206
207
208 citations;
209
210 do {
211 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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26