贴一个批量下载脚本

在网上下载时,可以发现有些有规律的连接,如以递增数字命名

http://xx...xx/chapter01.pdf

http://xx...xx/chapter02.pdf

....

http://xx...xx/chapter99.pdf

 

上面的连接模板为

http://xx...xx/chapter{}.pdf

把{}依次替换为01到99下载即可

 

下面这个脚本完成这个功能

 

#!/bin/bash

 

usage()

{

echo "usage:" >&2

echo "`basename $0` [-p positionwidth] urltemplate min max" >&2

exit 0

}

 

replace()

{

ins=$2

while [ $3 -gt ${#ins} ]; do

ins="0$ins"

done

echo $1 | sed -e "s/{}/$ins/"

}

 

poswid=0

while getopts ":p:" opt;

do

case $opt in

p)

poswid=$OPTARG

;;

?)

echo "invalid option -$OPTARG" >&2

usage

;;

esac

done

 

shift $((OPTIND-1));

if [ $# -ne 3 ]; then

usage

fi

 

urltpl="http://${1#http://}"

min=$2

max=$3

for i in `seq $min $max`

do

url=`replace $urltpl $i $poswid`

wget $url

done

按如下用法可批量下载上面提到的pdf文件
multiget -p 2 http://xx...xx/chapter{}.pdf 1 99
如果命名里面的递增数据没有对齐,则可以不需要-p参数,即
multiget http://xx...xx/chapter{}.pdf 1 99
可以下载
http://xx...xx/chapter1.pdf 
http://xx...xx/chapter2.pdf 
...
http://xx...xx/chapter99.pdf 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值