LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2217|回复: 2

关于漫画下载

[复制链接]
发表于 2009-10-2 19:01:40 | 显示全部楼层 |阅读模式
今天在起点上看到有阳神的漫画版本,想将其下下来,但是从网页的源代码上看到图片的文件名不是连在一起,也没什么规律。想到下面的办法解决:
先得到起点中漫画的目录页
wget http://www.qidian.com/BookReader/1322325.aspx
从上面的文件中得到其中最关键的一行
cat 1322325.aspx | sed -n '/BookReader/w temp.txt'
再分析出图片文件名(1322325是整个漫画的ID)
cat temp.txt | grep -o "1322325,[0-9]*" | awk -F , '{print $2}' > yangshen.txt
现在就可以下载漫画了
for i in `cat yangshen.txt`;do wget http://image.cmfu.com/books/1322325/$i.jpg;done
下载完后清理工作
rm 1322325.aspx temp.txt yangshen.txt

注:上面在下载时可以在后面加&让其同步下载,但数目我不知道怎么限定~~~当对服务器请求过多时会出问题的,所以哪位高手能改进一下

发现gqview看漫画是个不错的选择:)

script(添加了更新功能,即在不删除原来文件时再次运行只下载网上刚更新的章节)
  1. #/bin/bash
  2. # you can modify bookname for your book here, it will be the folder that include pictures
  3. bookname=yangshen
  4. # you can modify url here
  5. directoryurl=http://www.qidian.com/BookReader/1322325.aspx
  6. if [ ! -d $bookname ];then
  7.         mkdir $bookname
  8. fi
  9. cd $bookname
  10. baseurl=`basename $directoryurl`
  11. bookid=${baseurl%.*}
  12. if [ -f $baseurl ];then
  13.         echo "baseurl alread exits,remove it"
  14.         rm $baseurl
  15. fi
  16. wget $directoryurl 2>/dev/null
  17. if [ $? == 0 ];then
  18.         echo "Downloading menulist "$baseurl"                [SUCCESS]"
  19. else
  20.         echo "Downloading menulist "$baseurl"                [FAIL]"
  21.         exit 1
  22. fi
  23. cat $baseurl | sed -n '/BookReader/w temp.txt'
  24. if [ -f $bookname ];then
  25.         echo "book list file has alread exists, backup it first"
  26.         mv $bookname $bookname"_bak"
  27. fi
  28. cat temp.txt | grep -o "$bookid,[0-9]*" | awk -F , '{print $2}' > $bookname
  29. if [ -f $bookname"_bak" ];then
  30.         echo "this book has alread download, I will only update data"
  31.         if [ `wc -l $bookname | awk '{print $1}'` -gt `wc -l $bookname"_bak" | awk '{print $1}'` ];then
  32.                 echo "there is new capter catched."
  33.                 diff -ruN $bookname"_bak" $bookname | grep -o ^+[0-9].* | awk -F + '{print $2}' > temp2.txt
  34.         else
  35.                 echo "there isn't new capter catched"
  36.                 rm $baseurl temp.txt $bookname"_bak"
  37.                 exit 0
  38.         fi
  39.         rm $bookname"_bak"
  40. else
  41.         echo "this is the first time to download"
  42.         cp $bookname temp2.txt
  43. fi
  44. echo "Downloading comics "$bookname"..."
  45. for i in `cat temp2.txt`;do
  46. wget http://image.cmfu.com/books/$bookid/$i.jpg 2>/dev/null;
  47. if [ $? == 0 ];then
  48.         echo $i.jpg"                                        [SUCCESS]"
  49. else
  50.         echo $i.jpg"                                        [FAIL]"
  51. fi
  52. done
  53. rm $baseurl temp.txt temp2.txt
  54. echo "Download finish!"
复制代码
发表于 2009-10-2 21:37:02 | 显示全部楼层
嘿嘿,这个shell脚本很实用啊。
回复 支持 反对

使用道具 举报

发表于 2009-10-3 19:42:53 | 显示全部楼层
http://www.qidian.com/BookReader/1322325.aspx
页面中链接的代码:
<A href="1322325,24523011.aspx"> 03 草堂笔记</A>
对应图像地址:
http://image.cmfu.com/books/1322325/24523011.jpg

用文本编辑器或地址栏调试js给页面链接做简单的字符替换就能得到图片文件的url列表了...
用脚本写个循环按页面中图片链接出现的顺序依次命名为1.jpg,2.jpg...这样可以直接用看图软件播放...
或者就保持原来的文件名...页面源码再替换一下指向本地文件就可以当做本地htm导航...自己用htm写个frame...左分栏是导航页...图片显示在右分栏...这样用浏览器就可以阅读...

我下载小说漫画啥的都是这么干得...嘿嘿~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表