YH's Blog

Will be updated soon.
Google
 

Tuesday, April 01, 2008

 

get_image.pl

use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;
use IO::File;
my $url=shift or die "usage: $0 url\n";
if($url!~/^http:/i){$url="http://".$url;}
print $url,"\n";
my $ua=LWP::UserAgent->new();
my $req=HTTP::Request->new(GET=>$url);
my $response=$ua->request($req);
if($response->is_error()){print $response->status_line,"\n";}
else
{
$name="~~result.html";
open(FH,">$name") or die "Unable to create temp file:$!";
print FH "<HTML><TITLE>Perl's Good</TITLE><BODY>\n";
$count=0;
$content=$response->content();
while($content=~/src=\s*"?(\S+\.jpe?g)"?/cig)
{
print FH "<IMG src=$1 />\n";
$count++;
}

print FH "</BODY></HTML>";
if($count)
{
if(`echo %OS%`=~/windows/ig){`explorer $name`;}
else{`firefox $name`;};
}
print $count," pictures\n";
}

Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

July 2006   August 2006   September 2006   October 2006   August 2007   November 2007   March 2008   April 2008   May 2008   October 2008  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]