machine的blogma2ma.blog.chinaunix.net
machine
全部博文(142)
vim(8)
命令使用(5)
lfs(15)
测试程序(1)
cookbook学习(20)
2011年(8)
2010年(7)
2009年(64)
2008年(63)
xiaoyu98
好儿
jelon521
yviihfw
Bsolar
zzhen201
ghostwwl
llplg
lemontre
jiqing10
nanshanj
分类:
2009-03-31 17:17:51
#!/usr/bin/perl -w#--------------------------------------------------#author :空气人儿#blog :空气人儿#last update :2/13/2009#Tested in :Winxp Perl v5.10.0#TO DO : a lot#version :v.1.1#--------------------------------------------------use strict;use warnings;use LWP::UserAgent;use HTML::TreeBuilder;use HTML::Element;use HTML::Entities;use Encode qw(encode);use HTTP::Cookies::Microsoft;use Win32::TieRegistry(Delimiter => "/");#Set default values#--------------------------------------my $blog_username = "你的用户名";my $blog_password = "你的密码";#main program#--------------------------------------#get cookies from local IE cookies files.#Attention!#This part will open your IE,but never mind it.#and it's not needed if you had saved your cookies in your local IE.#-----------------------------------------------------------------------my $url = "http://passport.baidu.com/?login&username=$blog_username&password=$blog_password&mem_pass=on"; system "start iexplore.exe \"$url\""; sleep 15;#-----------------------------------------------------------------------my $cookies_dir = $Registry->{"CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Cookies"};my $cookie_jar = HTTP::Cookies::Microsoft->new( File => "$cookies_dir\\index.dat", 'delayload' => 0, );my $ua = LWP::UserAgent->new; $ua->timeout(60); $ua->cookie_jar( $cookie_jar );#get blog category to hashmy %hash = Blog_categoryhash($blog_username);#backup blog files incording to their categoryBlog_category_backup();#subroutine#------------------------------------------------------------------------sub Blog_category_backup{ my $key; my $value; while (($key,$value) = each (%hash)) { my $req = new HTTP::Request(GET => ""); my $res = $ua->request($req); if ($res->is_success) { open FH,">$key .html"; print FH $res->content; close FH; } else { die $res->status_line; } }}sub Blog_categoryhash { my($blog_user) = shift; my %blog_category_link; # my $ua = LWP::UserAgent->new(); # $ua->timeout(60); my $req = HTTP::Request->new(GET=>"$blog_user/blog"); my $res = $ua->request($req); my $content = $res->decoded_content(); my $tree = HTML::TreeBuilder->new(); $tree->parse($content); my $body = undef; my @div = $tree->look_down( _tag => 'div', class => 'item', sub { my $link = $_[0]->look_down('_tag','a'); return 1 unless $link; return 1 if $link->attr('href') =~ m{/category/}; return 0; } ); foreach my $div(@div){ my $tempbody = $div->as_HTML(); if($tempbody =~m/href=\"(.*?)\" title=\"(.*?)\"\>(.*?)\<(.*?)\((.*?)\)/) { my $cate_name = encode('gb2312', decode_entities($3)); my $cate_link = $1; $blog_category_link{$cate_name} = $cate_link; if($5 > 15) { my $biaohao = int($5/15); while($biaohao >= 1) { my $linkend = "/index/$biaohao"; $blog_category_link{$cate_name.$biaohao} = $cate_link.$linkend; $biaohao--; } } } } $tree = $tree->delete; return %blog_category_link;}
上一篇:揭秘会变化人数的图
下一篇:Vi指令大全(转)
登录 注册