【Shell】模拟爬虫下载天龙八部小说

Shell脚本: 

#curl https://tianlong.5000yan.com/ -o tianlong.html
grep "href=" tianlong.html | grep html | awk -F"\"" '{ print $6 }' >> urls.txt
grep "href=" tianlong.html | grep html | awk -F">" '{ print $3 }' | awk -F"<" '{ print $1 }' >>titles.txt

#为啥要从3开始,为啥不用0,1,2
#0,1,2 被系统占了
#
#一般情况下,每个 Unix/Linux 命令运行时都会打开三个文件:
#
#标准输入文件(stdin):stdin的文件描述符为0,Unix程序默认从stdin读取数据。
#标准输出文件(stdout):stdout 的文件描述符为1,Unix程序默认向stdout输出数据。
#标准错误文件(stderr):stderr的文件描述符为2,Unix程序会向stderr流中写入错误信息。
#所以得从3开始                        
#原文链接:https://blog.youkuaiyun.com/qq_35423190/article/details/112511373

exec 3<urls.txt
exec 4<titles.txt

#-u 后面跟fd,从文件描述符中读入,该文件描述符可以是exec新开启的。
while read -u 3 url && read -u 4 title
do
	echo "$title : $url"
	curl "$url" -o "${title}.html"
done

下载后的文件:

下载后的效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值