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:-)