use strict; use WWW::Mechanize; use Data::Dumper; my $url = 'http://gree.jp/'; my $id = 'hoge@hoge.org'; my $pass = 'password'; our $q = WWW::Mechanize->new(); our $dir = 'log/'; my $att = '?action=login'; $q->get($url.$att); $q->form_number(1); $q->set_fields( user_mail => $id, user_password => $pass, ); my $response = $q->submit(); sleep(1); $att = '?action=home'; $q->get($url.$att); our $fileid = 1; our %link_list = (); my %listid_list = (); $q->follow_link( url_regex => qr{http://gree.jp/[^/]+/blog} ); $q->uri =~ m{http://gree.jp/([^/]+)/blog}; my $myid = $1; mkdir($dir) if(! -e $dir); print "listing from ", $q->uri, "\n"; &get_comments(); while( $q->follow_link( url_regex => qr{^$url$myid/blog/\d+$}i) ){ print "listing from ", $q->uri, "\n"; $q->uri =~ m{^$url$myid/blog/(\d+)$}; exit if($listid_list{$1}); $listid_list{$1} = 1; &get_comments(); } sub get_comments{ my $i = 1; while( $q->follow_link( url_regex => qr/\#comment/i, n => $i) ){ if($link_list{$q->uri}){ $i++; $q->back; next; } print " ", $q->uri, "\n"; $link_list{$q->uri} = 1; my $filename = $dir . sprintf("%03d", $fileid). ".html"; open S, ">$filename"; print S $q->content; close S; $i++; $fileid++; $q->back; } }