Linux Shell Programming Combat---Shell implementation image download artifact

Source: Internet
Author: User

$ 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;&NBSP;WOW64)  AppleWebKit/535.24  (Khtml, like gecko)  Chrome/19.0.1055.1  safari/535.24 "  curl -s -o tmp.html -H " user-agent:  $UA "  $1   u= ' cat tmp.html|grep -e -o  "/html/63/[0-9]+\.html\"  target=\ "_blank\" > &LT;SPAN&GT;[0-9]{2}-[0-9]{2}</span> "|sed  ' s/ /_/  '   for line in  $u   do      #echo   $line     url= ' echo  $line |grep -e -o   "/html/63/[0-9]+\.html" '     datetime= ' echo  $line |grep -e -o  "[ 0-9]{2}-[0-9]{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 -s -o  tmp.html -h  "user-agent:  $UA"   $1  title= ' cat tmp.html|grep -e  -o  "<title>.*</title>" |sed  ' s/[<title>|</title>]//g '    Datetime=$2  img_url= ' Cat tmp.html|grep -E -o  "Https://img.997pp.com/tp/[0-9]{4}/[0-9]{2}/[a-za-z0-9]+.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 -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 5done


This article is from the "operation and maintenance of micro-letter" blog, please be sure to keep this source http://weixiaoxin.blog.51cto.com/13270051/1964208

Linux Shell Programming Combat---Shell implementation image download artifact

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.