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