Shell script Implementation bulk download network picture code sharing _linux Shell

Source: Internet
Author: User
Tags curl

Recently, in order to do a weather forecast project, need to download some weather icons from Yahoo, but because of more than 80 icons. The icons are stored on the Yahoo image site.

Thunder does not support HTTPS downloads, although it can be downloaded in the browser, but in the browser download is too slow, so write a batch download picture resources shell Script, the perfect solution to this problem.

Yahoo weather icon address rules are as follows: https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/+ icon Name

Like what:

I used 2 methods to solve the problem of downloading, although for a long time did not write shell script, but the consciousness and the foundation still, write that dozens of lines of code is relatively easy.

Method 1:

#!/bin/bash
# 
decription: 
#  A Shell script used to download the imges from the Internet.
# Author:
#  Long Luo
# Date:
#  2014-09-11 00:16:59
#

base_url= ' https://s.yimg.com/ zz/combo?a/i/us/nws/weather/gr/"

# DECLARE STIRNG variable
string=" beginning Image download ... "

Print var on screens 
Echo $STRING sleep

1
echo "big_png=" Ds.png "png=".
PNG "

echo" Url= ' ${base_url}
echo ' Big png= ' ${big_png} for

((i=0; i<49;i++)); Do
 echo img_url=${base_url}${i}$ {Big_png}
 echo "Final Url=" ${img_url}

 Curl ${base_url}${i}${big_png}-o small/${i}${png} sleep
 1 done

Method 2:

Method 2 Write the image URL address in an array, and then read from the array, and rename, relatively speaking, the first method is less simple:

# method 2

url_array= (
' https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/0d.png '
https:// S.yimg.com/zz/combo?a/i/us/nws/weather/gr/1d.png '
)

name_array= (
' file1.jpg '
file2.jpg '
)

elements=${#URL_ARRAY [@]} for

((i=0;i<elements;i++); does
 echo ${url_array[${i}]}
 Echo Saved as ${name_array[${i}]} "
 Curl ${url_array[${i}]}-o images/${name_array[${i}]}"} Sleep 1 is done

Above, hope to have the need of schoolmate can adopt:-)

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.