pixnet相簿備份程式


前言
哈,好東西來了,各位網友們,你們想備份pixnet上的相簿嗎?我花了點時間寫了一個可以抓pixnet的小程式,希望大家會喜歡。為什麼我會想寫這個程式呢?因為在pixnet的首頁上常常看到一些不錯的照片,想用滑鼠右鍵另存她的圖又不行,一張一張抓也太慢了,flashget沒試,不知道行不行,想想自己搞一個好了,就是這樣。又是perl寫的小東東,有興趣的可以留言一起研究喔:)
現在以我的相簿來示範一下

程式碼
use WWW::Mechanize;
use HTML::TreeBuilder;

my $userid="jck11";

my $mech = WWW::Mechanize->new;
$mech->get("http://www.pixnet.net/home/$userid");
my $albumlink_base=$mech->base;
$mech->success or die "post failed: ", $mech->response->status_line;

my @links=$mech->find_all_links(url_regex=> qr/\/album\/$userid\/[\d]{6,}/);
for(my $i=0; $i<=$#links; $i++){
my $albumlink=URI->new_abs($links[$i][0], $albumlink_base);
#print "albumlink: ", $albumlink, "\n";
$mech->get($albumlink);
$mech->success or die "post failed: ", $mech->response->status_line;
my $content=$mech->content;

my @photourl=$mech->find_all_links(url_regex=> qr/\/photo\/$userid\/\d+/);
$mech->success or die "post failed: ", $mech->response->status_line;
my $photolink_base=$mech->base;
for(my $j=0; $j<=$#photourl; $j++){
my $photolink=URI->new_abs($photourl[$j][0], $photolink_base);
#print "photolink: ", $photolink, "\n";
$mech->get($photolink);
$mech->success or die "post failed: ", $mech->response->status_line;
$mech->content=~ /http\:\/\/p1\.p\.pixnet\.net(.*)\.jpg/;
my $imgurl='http://p1.p.pixnet.net'.$1.'.jpg';
my $filename=(split(/\//, $imgurl))[-1];
print $imgurl, "\n";
#print "imgurl: ", $imgurl, "\n";
#print $filename, "\n";
$mech->get($imgurl, ":content_file"=>$filename);
}

my $p=HTML::TreeBuilder->new_from_content($content);
my @pagelinks=$p->look_down(
_tag=>'a',
class=>'pageNumber',
href=> qr{\/album\/$userid\/\d+\/\d+}x
);
$p->delete;
my $pagelink_base=$albumlink_base;
if($#pagelinks > 0){
for(my $k=0; $k<=$#pagelinks/2; $k++){
my $pagelink=URI->new_abs($pagelinks[$k]->attr('href'), $pagelink_base);
#print "pagelink: ", $pagelink, "\n";
$mech->get($pagelink);
$mech->success or die "post failed: ", $mech->response->status_line;
my @photourl=$mech->find_all_links(url_regex=> qr/\/photo\/$userid\/\d+/);
$mech->success or die "post failed: ", $mech->response->status_line;
my $photolink_base=$mech->base;
for(my $j=0; $j<=$#photourl; $j++){
my $photolink=URI->new_abs($photourl[$j][0], $photolink_base);
#print "photolink: ", $photolink, "\n";
$mech->get($photolink);
$mech->success or die "post failed: ", $mech->response->status_line;
$mech->content=~ /http\:\/\/p1\.p\.pixnet\.net(.*)\.jpg/;
my $imgurl='http://p1.p.pixnet.net'.$1.'.jpg';
my $filename=(split(/\//, $imgurl))[-1];
print $imgurl, "\n";
#print "imgurl: ", $imgurl, "\n";
#print $filename, "\n";
$mech->get($imgurl, ":content_file"=>$filename);
}
}
}

}

說明
如果想抓別人的照片,只要改這裡
my $userid="jck11";
jck11改成別人的帳號就行了,夠簡單了吧 :)
或許$mech->content=~ /http\:\/\/p1\.p\.pixnet\.net(.*)\.jpg/;這裡可能也要改
因為我沒一個一個相本去測是否都放這個目錄

進一步
這程式還有些沒考慮週詳之處,有些程式碼也是重複,可能也有些bug,等我有空時再來改,不過應足以應付相本不是很多的相簿了。如果你不沒裝perl的話就沒法跑這個程式,如果有人想知道怎麼裝的話可上網找找,應該很多資料,或許也可留言給我,我再來寫篇如何安裝的文章,有其他bug的話,請跟我說一下,就螿啦。

成果展示
這是我用程式跑出來的連結,當然照片也下載到硬碟上了,我把連結給掛下來,有flashget的人直接把連結copy走就能抓了 :)
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153795.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153796.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153797.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153798.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153799.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153800.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153801.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153802.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153803.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153804.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153974.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153975.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153976.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153977.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153978.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153979.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153980.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153981.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153982.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179153983.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154191.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154192.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154193.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154194.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154195.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154196.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154197.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154198.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154199.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154200.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154357.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154358.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154359.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154360.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154361.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154362.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154363.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154364.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154365.jpg
http://p1.p.pixnet.net/albums/userpics/1/6/439116/1179154366.jpg
創作者介紹

神鵰蝦

jck11 發表在 痞客邦 PIXNET 留言(0) 人氣()