有点XX,就不写注释了,留给有缘人自己看吧^_^ use strict; use LWP::Simple; use Data::Dumper qw(Dumper); $Data::Dumper::Indent = 1; use HTML::TokeParser; my $numArgs = $#ARGV + 1; print "thanks, you gave me $numArgs command-line arguments:/n"; #foreach my $argnum (0 .. $#ARGV) { # # print "$ARGV[$argnum]/n"; # #} #my $url = "http://www.94xiezhen.com/meinv/meinvtupian/201009/21-10022.html"; #my $max_page = 4; #mkdir "./中文"; my $url = $ARGV[0]; my $max_page = $ARGV[1]; my $local_save_path = $ARGV[2]; my $html_path = "./htmltmp"; sub get_jpg_from_url($) { my $url = shift; if ($url=~/http/:[a-zA-Z0-9/-/.]+/.com[/:/d+]*.*//([a-zA-Z0-9/-/_]+/.html)/){ my $filename= sprintf("./%s/%s",$html_path, $1); my $code = getstore($url, $filename); open IN_FILE, "<$filename" or die("Could not open $filename"); my $file = /*IN_FILE; my $parser = HTML::TokeParser->new($file) or die "Can't open $file: $!/n"; my @images; while (my $token = $parser->get_token( )) { my $type = $token->[0]; if ( $type eq 'S' ) { if ( $token->[1] eq 'img' ) { push @images, $token->[2]{'src'}; } } } print Dumper(/@images), "/n"; foreach my $image(@images){ if ($image=~/http/:[a-zA-Z0-9/-/.]+/.com/:/d+.*//([a-zA-Z0-9/-]+/.jpg)/){ print $1, "/n"; my $imgpath=sprintf("./%s/%s",$local_save_path, $1); my $code = getstore($image, $imgpath); #获取URL指定的图片,并保存 } } } } sub get_94xx_all_jpg($) { my $url = shift; my $max_page = shift; #get filename my $filename_base; my $filename_ext; my $url_path; if ($url=~/(http/:[a-zA-Z0-9/-/.]+/.com[/:/d+]*.*//)([a-zA-Z0-9/-/_]+)/.(html)/){ $url_path = $1; $filename_base = $2; $filename_ext = $3; } print $url,"/n"; get_jpg_from_url($url); my $i = 0; for ($i=2; $i<$max_page+1; $i++){ my $url_other = sprintf("%s%s_%d.%s", $url_path, $filename_base, $i, $filename_ext); print $url_other,"/n"; get_jpg_from_url($url_other); } } mkdir "./$local_save_path"; get_94xx_all_jpg($url, $max_page);