my $mainwin=new MainWindow; $mainwin->title("HUABAN DOWNLOADER");
#在mainwin上添加一个Frame1 my $board_idF=$mainwin->Frame(); $board_idF->pack(-expand=>1,-fill=>"both",-side=>"top"); #在Frame1 上添加一个label my $board_idL=$board_idF->Label(-text=>"The board id:",-width=>50,-anchor=>'w'); $board_idL->pack(-side=>"left"); #在Frame1 上添加一个文本框Entry my $id_VAR=20194339; my $id_Ent=$board_idF->Entry(-textvariable=>\$id_VAR); $id_Ent->pack(-side=>'left');
#在mainwin上增加一个Frame ,存放下载图片数目 my $num_F=$mainwin->Frame(); $num_F->pack(-expand=>1,-fill=>'both',-side=>'top'); my $num_VAR=200;
$num_F->Label(-text=>"number of photos to downloaded:",-width=>50,-anchor=>'w')->pack(-side=>'left'); my $num_Ent=$num_F->Entry(-textvariable=>\$num_VAR); $num_Ent->pack(-side=>'left');
#在mainwin上增加Frame2 my $dir_F=$mainwin->Frame(); $dir_F->pack(-expand=>1,-fill=>"both",-side=>"top"); #在Frame2 增加一个Label $dir_F->Label(-text=>"Output Dictory:",-width=>50,-anchor=>'w')->pack(-side=>'left'); #Frame2 增加一个Button my $dir=""; $dir_F->Button(-text=>"browse...",-width=>15, -command=>sub{&selectdic})->pack(-side=>'left'); #Frame2 增加一个Label my $dirL=$dir_F->Label(-text=>"No dictory Selected."); $dirL->pack(-side=>'left');
use Mojo::UserAgent::CookieJar; my $ua = Mojo::UserAgent->new(); my $browser='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.2.2000 Chrome/30.0.1599.101 Safari/537.36';
$ua->transactor->name($browser); my $cookie_jar = $ua->cookie_jar;
my $starturl='http://huaban.com/boards/'.$board_id; my $body; my $jsonbody; my ($pin_id,$key); my ($pngurl,$pngfile); my $baseurl='http://hbimg.b0.upaiyun.com/'; while(1) { $body=$ua->get($starturl)->res->body; while($body=~/"pin_id":(\d+),.*?"key":"(\S+?)",/msg) { ($pin_id,$key)=($1,$2); print $pin_id,"\n"; $pngurl=$baseurl.$key.'_fw658'; #print "pngurl: $pngurl\n"; $pngfile=$pin_id.'.jpg'; if($directory=~/No directory/) {