PerlJam has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use HTML::SimpleLinkExtor; use LWP::Simple; use Image::Grab; my $save_dir = ">/home/dir/"; my $page = 'http://website.com/webpage.html'; my $link; my $image; my $counter = 0; my $pic = Image::Grab->new(); my $html = get($page); my $extor = HTML::SimpleLinkExtor->new(); $extor->parse($html); my @page_links = $extor->links; my @temp = split(/\//, $page); pop(@temp); my $page_dir = join('/', @temp) . "/"; @temp =""; print "$page_dir\n"; foreach $link (@page_links) { if ($link =~ /jpg$/) { next if $link =~ /small.jpg$/; print $link . "\n"; $counter++; my @temp = split(/\//, $link); my $filename = pop(@temp); #Here is the suspect code if (-e "${save_dir}${filename}") { print "$filename exists, skipping file"; next; } print "Save Dir = ${save_dir}${filename}\n"; print "Image URL = ${page_dir}${link}\n"; $pic->url($page_dir . $link); $pic->grab; open(IMAGE, "${save_dir}${filename}") || die "$!"; print IMAGE $pic->image; close IMAGE; print "${counter}: Saved $link \n\n"; } } print "Finished!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Failed file existance check
by rchiav (Deacon) on Apr 29, 2001 at 10:22 UTC | |
by PerlJam (Sexton) on Apr 30, 2001 at 02:25 UTC | |
|
Re: Failed file existance check
by olly (Scribe) on Apr 29, 2001 at 14:06 UTC |