0: # A program to download a lot of images from a site
1: # quickly using LWP::Simple. Assuming you have appropriate
2: # permission, etc to download the images, and that the
3: # images have sequential names (like img_001.jpg,
4: # img_002.jpg...), this program will load those images
5: # into the current folder. You have to have the
6: # LWP::Simple module for this to work. -tim allen
7:
8: use LWP::Simple;
9: use strict;
10:
11: # first part of the URL of the image
12: # replace the URL and path info here appropriately
13: my($pix)='http://tim/images/img_';
14:
15: for (my $i=1;$i<100;$i++) {
16: # this bit assumes the numbers of the files are zero
17: # padded to three zeroes (thanks btrott for sprintf
18: # pointer)
19: my $f = sprintf '%03d',$i;
20: # create the full URL of the image
21: # (like http://www.somesite.com/images/img_001.jpg)
22: my $url = $pix . $f . ".jpg";
23: # If we get the header, the image file exists
24: if (!head($url)) {
25: warn "sorry, $url doesn't exist\n";
26: } else {
27: # it exists, so get it and store it
28: getstore($url,"img_$f.jpg")
29: or warn "can't get image: $!";
30: # Print a progress message
31: print "$url successfully stored\n";
32: }
33: }
34: print "Done!\n"; In reply to Use LWP::Simple to download images from a website by zeno
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |