jonvi 发表于 2018-8-20 06:55:17

Linux Shell编程实战---shell实现图片下载神器

$ cat dowonload_image.sh  
#!/bin/bash
  
#########################################
  
#图片下载器                              #
  
#script_name: dowonload_image.sh         #
  
#author:weixiaoxin write by 2017-09-20   #
  
#########################################
  

  
function get_second_level_url(){
  
#declare -A url_array
  
UA="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"
  
curl -L -s -o tmp.html -H "User-Agent: $UA"$1
  
u=`cat tmp.html|grep -E -o "/Html/63/+\.html\" target=\"_blank\">{2}-{2}"|sed 's/ /_/ '`
  
for line in $u
  
do
  
    #echo $line
  
    url=`echo $line|grep -E -o "/Html/63/+\.html"`
  
    datetime=`echo $line|grep -E -o "{2}-{2}"`
  
    url_date+="$url,$datetime\n"
  
    #url_array[$url]=$datetime
  
done
  

  
echo${url_date}
  
}
  

  

  
function get_image(){
  
UA="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24"
  
curl -L -s -o tmp.html -H "User-Agent: $UA"$1
  
title=`cat tmp.html|grep -E -o ".*"|sed 's/[|]//g'`
  
datetime=$2
  
img_url=`cat tmp.html|grep -E -o "https://img.997pp.com/tp/{4}/{2}/+.jpg"`
  

  

  
if [ ! -d "data/${datetime}/${title}" ]
  
then
  
    mkdir -p data/$datetime/${title}
  
fi
  

  
n=1
  
for i in $img_url
  
do
  
    echo $i
  
    i=`echo $i|sed 's/https/http/g'`
  
    curl -L -s -o data/${datetime}/${title}/$n.jpg -H "User-Agent: $UA"$i
  
    sleep 2
  
    let n=n+1
  
    echo $n
  
done
  
}
  

  
baseurl="https://www.1368k.com/Html/63/"
  
first_url="${baseurl}index.html"
  

  
second_url=`get_second_level_url ${first_url}`
  

  
for line in `echo -e $second_url`
  
do
  
#echo $line
  
url=`echo $line|awk -F',' '{print $1}'`
  
url="https://www.1368k.com/$url"
  
datetime=`echo $line|awk -F',' '{print $2}'`
  
#echo $url $datetime
  
get_image $url $datetime
  

  
sleep 5
  
done


页: [1]
查看完整版本: Linux Shell编程实战---shell实现图片下载神器