# Parse the Web page to identify images
my %imagefiles;
my $parser = HTML::TokeParser->new(\$html);
while (my $img_info = $parser->get_tag('img')) {
my $image_name = $img_info->[1]->{'src'};
my $image_url = URI->new($image_name);
my $image_file = $image_url->abs($url);
$imagefiles{$image_file} = 1;
}
# Retrieve all the images and save them locally
foreach my $this_image (keys %imagefiles) {
$this_image =~ m{.*/(.*)$};
my $local_image_name = $1;
$local_image_name =~ tr/A-Za-z0-9./_/c;
my $local_image_path_name = "$images_path/$local_image_name";
my $image_data = get($this_image) || '';
# Get the images after checking if they don't already exist.
my $local_img = "$images_path/$local_image_name";
unless(-e $local_image_path_name)
{
my $image_data = get($this_image) || '';
# Save copy of image locally
open(OUTPUT_FILE, ">$local_image_path_name") || die "Unable to open $local_image_name: $!";
binmode(OUTPUT_FILE);
print OUTPUT_FILE $image_data;
close(OUTPUT_FILE);
#print "saved: $local_image_path_name
\n";
}# end of if image exists.
#print "local img is: $local_img
/n";
}