in reply to Re: Downloading image files using LWP
in thread Downloading image files using LWP
Here is the output when I run it the second time Getting imagefile: images/logo.gifwhile( my $url = shift @urls) { print "URL is $url\n"; my $request = HTTP::Request->new(GET => $url); my $parser = HTML::Parser->new(api_version => 3); $parser->handler(start => \&start,'self,tagname,attr'); my $response = $browser->request($request); if ($response->is_success) { print $response->content(); $parser->{base} ||= $response->base; $parser->{browser} ||= $browser; $parser->parse($response->content); $parser->eof(); } else { print "ERROR: " . $response->status_line . "\n"; } } sub start + { my ($parser,$tagname,$attr)= @_; if ($tagname eq 'img') { if ($attr->{src}) + { + my $img_url = $attr->{src}; + my $remote_name =URI->new_abs($img_url,$parser +->{base}); #my ($local_name) = $img_url =~ m!([^/]+)$!; + my $local_name = $remote_name->host . $remote_ +name->path ; + #my $local_name = "/dev/null"; + mkpath(dirname($local_name),0,0711); + print "Getting imagefile: $img_url\n"; + my $response = $parser->{browser}->mirror($rem +ote_name,$ local_name); + print STDERR "YYY-$local_name: ",$response->me +ssage,"\n" ; + } + } + }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Downloading image files using LWP
by iburrell (Chaplain) on Nov 06, 2002 at 02:01 UTC | |
by gnangia (Scribe) on Nov 06, 2002 at 18:37 UTC | |
|
Re: Re: Re: Downloading image files using LWP
by HamNRye (Monk) on Nov 06, 2002 at 00:07 UTC | |
|
Re: Re: Re: Downloading image files using LWP
by petral (Curate) on Nov 06, 2002 at 00:04 UTC |