2 ###APPNAME: book_download.pl
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Tue Mar 11 04:58:02 2008
6 ###APPDESC: download html using book_parser
7 ###APPUSAGE: indexURL [directory]
8 ###APPEXAMPLE: book_download http://book.sina.com.cn/nzt/lit/wodemingzijiaohong/index.shtml src
12 $ARGV[0]="-h" unless(@ARGV);
14 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
20 return "$base\/$href" if($href =~ /^[^\
/]/);
21 $base =~ s/(http:\/\/[^\
/]*)\/.*$/\1/;
27 open FI
,"-|","book_parser '$url'";
28 my $data = join("",<FI
>);
29 my $book = XMLin
($data,SuppressEmpty
=>1,NoAttr
=>1,KeyAttr
=>[]);
33 $base =~ s/\/[^\/]*$//g;
40 $book->{title
}=$name unless($book->{title
});
44 $saveto=$book->{author
} . "/" . $book->{title
};
45 if(! -d
$book->{author
}) {mkdir $book->{author
} or die("$!\n");}
48 $saveto=$book->{title
};
50 if(! -d
$saveto) {mkdir $saveto or die("$!\n");}
55 mkdir $saveto or die("$!\n");
59 open fO
,">","bookinfo.xml";
63 open fO
,"|-","batchget -n '$book->{title}' -r '$url'";
66 for(my $i=0;$i<@
{$book->{pages
}};$i++) {
67 print fO buildURL
($base,$book->{pages
}->[$i]->{url
}),"\n";
71 print STDERR
"Task done! Saved in $saveto\n";