- 论坛徽章:
- 0
|
用法,复制下面代码到down.pl,然后执行“./down.pl 相册用户名 相册ID Password”
- #!/usr/bin/perl
- #
- # File: down.pl
- # Author: blueirver
- use strict;
- use warnings;
- use LWP::UserAgent;
- use HTTP::Request::Common;
- use Encode;
- use File::Path;
- sub lwp_get($;%)
- {
- my ($url, %opt) = @_;
- my $uri = URI->new($url);
- my $referer = $uri->scheme."://".$uri->host.$uri->path unless (%opt || $opt{referer});
- my $useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1' unless (%opt || $opt{useragent});
- my $ua = LWP::UserAgent->new();
- my $req = HTTP::Request->new(GET => $url);
- $req->header('Host' => $uri->host);
- $req->header('User-Agent' => $useragent);
- $req->header('Referer' => $referer);
- $req->header('Cookie' => $opt{cookie});
- my $res = $ua->request($req);
- warn "fetch_page error! perhaps you should try again.\n" unless $res->is_success;
- if($opt{remote_charset} && $opt{local_charset} && ($opt{remote_charset} ne $opt{local_charset}))
- {
- return encode($opt{local_charset}, decode($opt{remote_charset}, $res->as_string));
- }
- return $res->as_string;
- }
- sub lwp_post($$;%)
- {
- my ($url, $form_ref, %opt) = @_;
- my $uri = URI->new($url);
- my $referer = $uri->scheme."://".$uri->host.$uri->path unless (%opt || $opt{referer});
- my $useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1' unless (%opt || $opt{useragent});
- my $cookie = ' ' unless (%opt || $opt{cookie});
- my $ua = LWP::UserAgent->new();
- $ua->default_headers->push_header('Host' => $uri->host,);
- $ua->default_headers->push_header('User-Agent' => $useragent,);
- $ua->default_headers->push_header('Referer' => $referer,);
- $ua->default_headers->push_header('Cookie' => $cookie);
- my $res = $ua->request(POST $url, Content => ${form_ref});
- warn "lwp_post faild!perhaps you supply a right password.\n" unless $res->is_success;
- return $res->as_string;
- }
- sub nease_split($)
- {
- my ($html) = @_;
- my (@hostids, @type, @name, @photoids);
- @name = $html =~ /\[\d\d\d,\d,"\d+x\d+","(.*)","http:\/\/.*","http.*"\]/g;
- my (@photos) = $html =~/\[\d\d\d,\d,"\d+x\d+",".*","http:\/\/.*","(http.*)"\]/g;
- return (\@photos, \@name);
- }
- my ($user, $aid, $pwd) = @ARGV;
- die "usage: $0 \$user \$aid [\$password]\n" if((not defined($user)) || (not defined($aid)));
- my $aurl = "http://photo.163.com/photos/$user/$aid/";
- my $iurl = "http://photo.163.com/js/photosinfo.php?user=$user&aid=$aid";
- my ($html, $cookie);
- if($pwd) {
- my %form = ('checking' => '1', 'pass' => $pwd);
- $html = lwp_post($aurl, \%form);
- ($cookie) = $html =~ /Set\-Cookie:(.*)/ig;
- }
- $html = lwp_get($iurl, (cookie => $cookie));
- my ($url_ref, $name_ref) = nease_split($html);
- #print $html;
- my $folder = "$user/$aid";
- mkpath($folder, 1, 0755);
- my $ret;
- foreach (0..$#${url_ref}) {
- print "\n$_/$#${url_ref} downloaded. ".$name_ref->[$_]."\n";
- next if(-f "$folder/".$name_ref->[$_+2]);
- $ret = `wget -c --referer=http://photo.163.com/photos/ $url_ref->[$_] -O \"$folder/$name_ref->[$_]\"`;
- }
复制代码
[ 本帖最后由 蓝色多瑙河1 于 2007-6-16 23:18 编辑 ] |
|