By long Luo
Recently
Weather ForecastProject, you need to download some weather icons from Yahoo, but because there are many icons, there are more than 80. Icons are stored on the Yahoo image website.
Thunder does not support HTTPS download. Although it can be downloaded in the browser, it is too slow to download in the browser. Therefore, a shell script for batch downloading image resources is written, which perfectly solves this problem.
The address rules for Yahoo weather chart are as follows: 'https: // s.yimg.com/zz/combo? A/I/US/NWS/weather/GR/'+ icon name
For example:
I used two methods to solve the problem of downloading. Although I haven't written shell scripts for a long time, I still have the awareness and foundation, and it is easier to write dozens of lines of code.
Method 1:
#!/bin/bash# # Decription: #A Shell script used to download the imges from 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 variableSTRING="Beginning Image download..."#print var on screen echo $STRINGsleep 1echo "...."BIG_PNG="ds.png"PNG=".png"echo "url="${BASE_URL}echo "big png="${BIG_PNG}for ((i=0; i<49;i++)); doecho IMG_URL=${BASE_URL}${i}${BIG_PNG}echo "final url="${IMG_URL}curl ${BASE_URL}${i}${BIG_PNG} -o small/${i}${PNG}sleep 1done
Method 2:
# Method 2URL_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++)); doecho ${URL_ARRAY[${i}]}echo "saved as ${NAME_ARRAY[${i}]}" curl ${URL_ARRAY[${i}]} -o images/${NAME_ARRAY[${i}]}sleep 1done
In the above example, we hope that you can use the following features :-)
Created by long Luo at 22:44:52 @ Shenzhen, China.
Completed by long Luo at 23:01:05 @ Shenzhen, China.
A shell script for batch download of network images