ZhuaShuShell 是基于shell的书籍自动下载工具,它能够自动整理成长篇txt格式书籍,方便电脑手机上阅读。
shell工具集是中国软件爱好者编写的一款非常不错的抓书工具。虽然是作者在平时看一些门户网站读书频道上连载的历史书,却懒得一页一页的翻Web,还要受网站广告骚扰不甚其烦下获得灵感而诞生的作品,但丝毫不影响该软件的实用程度。现在作者把这款用shell 脚本写的抓书工具,分享出来,相信肯定有热爱读书又买不起书的书生同好们需要的 :)
部分网站的软件使用说明
新浪(Sina)读书频道
#!/bin/bash
rm $3.txt
echo
echo "START"
i="1"
M="$[$2+1]"
while [ $i -lt $M ]
do
echo "Downloading Chapter $i..."
wget -p -q -nd $1/$i.shtml
cat ./$i.shtml | grep "<p>" > $i.txt
sed -i 's/<p>//g' $i.txt
sed -i 's/<\/p>/\
/g' $i.txt
sed -i 's/<[^<]*>//g' $i.txt
sed -i '/[:space:][^C]*/d' $i.txt
sed -i 's/^[[:space:]]*//g' $i.txt
cat $i.txt >> $3.txt
rm $i.txt
rm $i.shtml
i=$[$i+1]
done;
echo "END"
使用方法是将上文保存为sinatest,在bash shell下chmod 755 sinatest使其具有可执行权限.
./sinatest 书的路径 最后一章的号 保存的书名
要下载的是http://book.sina.com.cn/nzt/history/his/shijixindu/index.shtml上介绍的书,一共有384章,那么就这样使用:
./sinatest http://book.sina.com.cn/nzt/history/his/shijixindu 384 shiji
腾讯(QQ)读书频道
#!/bin/bash
rm $3.txt
echo
echo "START"
i="1"
M="$[$2+1]"
while [ $i -lt $M ]
do
echo "Downloading Chapter $i..."
wget -p -q -nd -A "*.shtml" $1/$i.shtml
cat ./$i.shtml | grep "<br /><br />" > $i.txt
sed -i 's/<[^<]*>//g' $i.txt
cat $i.txt >> $3.txt
echo >> $3.txt
rm $i.txt
rm $i.shtml
i=$[$i+1]
done;
echo "END"
保存为qqtest
要下载的是http://book.qq.com/s/book/0/10/10165上介绍的书
使用方法是:./qqtest http://book.qq.com/s/book/0/10/10165 20 hk
最后书会保存为hk.txt
雅虎(Yahoo)中国读书频道
#!/bin/bash
rm $2.txt
echo
echo "START"
wget -r -l 1 -A "*.html" -p -q -nd $1
cat *.html >> $2.txt
rm *.html
cat $2.txt | grep "<p>" >> $2
mv $2 $2.txt
sed -i 's/<p>//g' $2.txt
sed -i '/<p\ /d' $2.txt
sed -i 's/<[^<]*>//g' $2.txt
sed -i '/\ /d' $2.txt
echo "END"
保存为yahootest
要下载的是http://cn.news.yahoo.com/reading/cf319qjxc/index.html上介绍的书
使用方法是(注意这里不需要设置章节数):
./yahootest http://cn.news.yahoo.com/reading/cf319qjxc/index.html lcy
最后书会保存为lcy.txt
MSN中国读书频道
#/bin/bash
rm $2.txt
echo
echo "START"
wget -r -l 1 -A "*.html,*.shtml" -p -q -nd $1
rm *.html
cat *.shtml >> $2.txt
rm *.shtml
cat $2.txt | grep "<br>" > $2
mv $2 $2.txt
sed -i 's/<br>/\
/g' $2.txt
sed -i 's/<[^<]*>//g' $2.txt
sed -i 's/\ //g' $2.txt
echo "END"
保存为msntest
要下载的是http://msn.hongxiu.com/n/a/42385/上介绍的书
使用方法是 (注意这里不需要设置章节数,最后要加上一个/):
./msntest http://msn.hongxiu.com/n/a/42385/ kongzi
最后书会保存为kongzi.txt
猫扑(Mop)读书频道
#!/bin/bash
rm $2.txt
echo
echo "START"
wget -r -l 1 -A "*.html" -p -q -nd $1
cat *.html >> $2.txt
rm *.html
cat $2.txt | grep "<br>" > $2
mv $2 $2.txt
sed -i 's/\ //g' $2.txt
sed -i 's/<br>/ /g' $2.txt
sed -i 's/<[^<]*>//g' $2.txt
echo "END"
保存为moptest
要下载http://book.mop.com/ebook/NqWx5mdz.html上介绍的书
使用方法是 (注意这里不需要设置章节数):
./moptest http://book.mop.com/ebook/NqWx5mdz.html hxd
最后书会保存为hxd.txt
Wuhan读书频道
#!/bin/bash
rm $3.txt
i="1"
M="$[$2+1]"
ten="10"
echo
echo "START"
while [ $i -lt $M ]
do
echo "Downloading Chapter $i..."
if [ $i -lt $ten ]
then
wget -p -q -nd -A "*.htm" $1/0$i.htm
cat ./0$i.htm | grep "<p>" > $i.txt
rm 0$i.htm
else
wget -p -q -nd -A "*.htm" $1/$i.htm
cat ./$i.htm | grep "<p>" > $i.txt
rm $i.htm
fi
sed -i '/\ /d' $i.txt
sed -i 's/<p>//g' $i.txt
sed -i 's/<\/p>/\
/g' $i.txt
sed -i 's/<[^<]*>//g' $i.txt
sed -i 's/^[[:space:]]*//g' $i.txt
cat $i.txt >> $3.txt
rm $i.txt
i=$[$i+1]
done;
echo "BYEBYE"
保存为wuhantest
要下载的是http://book.wuhan.net.cn/xh/gcd1/gcd1.htm上介绍的书
使用方法是(注意这里地址的变化,需要设置章节数):
./wuhantest http://book.wuhan.net.cn/xh/gcd1 60 gcd1
最后书会保存为gcd1.txt
相关代码可以在Sourceforge上下载,地址是:http://sourceforge.net/projects/zhuashushell
声明:LUPA开源社区刊登此文只为传递信息,并不表示赞同或者反对。

迷你博客
日志
相册
群组
分享
电影
问答
停车游戏
奴隶游戏
开源大搜索
项目点评
礼品中心
职业评测
开源博客
新闻阅读
LUPA教程
考试练习
LW3DK开发
开源论坛
下载频道



