WWW::Mechanizeを使ってみた
毎度お馴染み画像取得スクリプト
#!/usr/bin/perl use strict; use warnings; use Time::HiRes; use IO::Handle; use File::Basename; use WWW::Mechanize; my $url = shift @ARGV or die "Error: please input url\n"; my $mech = WWW::Mechanize->new(); $mech->get( $url ); die "Can't download $url\n" unless $mech->success(); my @links = $mech->links(); my @jpgs = grep { $_->url =~ /.jpg$/; } @links; foreach my $jpg ( @jpgs ) { my $jpg_url = $jpg->url; my $file = basename($jpg_url); $mech->get( $jpg_url, REFEREF => $url ); next unless $mech->success(); print "Output $file... \n"; open my $fh, ">", $file or die "Can't open file\n"; $fh->print( $mech->content ); close $fh; sleep 0.5; }
これだと LWP::UserAgentを使っても大して変わりませんね。
WWW::Mechanizeを活かそうとすると、FORMの操作とかページの
遷移を含むものでないとね。もうちょっと凝ったものを作って
見ることにします。