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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26