溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

shell腳本如何實(shí)現(xiàn)獲取圖片

發(fā)布時(shí)間:2021-11-08 11:39:51 來源:億速云 閱讀:325 作者:小新 欄目:云計(jì)算

這篇文章主要介紹了shell腳本如何實(shí)現(xiàn)獲取圖片,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

shell腳本實(shí)現(xiàn)獲取圖片。

#!/usr/bin/bash

. /etc/init.d/functions

function check(){

time=`date "+%F %X"`

echo "當(dāng)前時(shí)間:$time"

ip=$(ip a |grep inet |grep "scope global dynamic"|awk -F"/" '{print $1}' |awk '{print $2}')

ping -w1 -c1 www.baidu.com &>/dev/null

if [[ $? -ne 0 ]];then

echo_failure || echo "網(wǎng)絡(luò)異常,請檢查"

else

echo_success && echo "網(wǎng)絡(luò)正常 當(dāng)前IP:$ip"

fi

yum repolist &>/dev/null

if [[ $? -ne 0 ]];then

echo_failure || echo "yum異常,請檢查"

fi

}

function down(){

yum install -y wget &>/dev/null

w=`echo "$1" |tr -d '\n' |od -An -tx1|tr ' ' %`

data=$(curl -s "https://image.baidu.com/search/index?tn=baiduimage&word=$w")

echo $data | grep -P -o "https://ss.*?.jpg" | sort -n -r |uniq >> $2/url2.txt

a=0

while read line

do

sleep 1

code=$(curl -I "$line" 2>/dev/null)

if [ ${code:9:3} -eq 200 ];then

wget -O $2/$1${a}.jpg $line &>/dev/null

echo "下載完成 $line"

else

echo "無效資源 $line"

fi

let a++

done <$2/url2.txt

echo "全部下載完成,下載資源$a個(gè)"

return 200

}

function clea(){

echo "正在打包,請稍后"

sleep 2

tar cvzf image.tar.gz $1

rm -rf $1/url2.txt

}

function main(){

check

down $1 $2

if [[ $? -eq 200 ]];then

clea $2

return 100

else

echo "下載異常,正在清理環(huán)境"

rm -rf $2

return 101

fi

}

clear

echo -e "本程序功能為獲取圖片: 圖片\n禮貌爬取,快樂你我他\n程序設(shè)計(jì)目的:shel腳本#!/usr/bin/bash

. /etc/init.d/functions

function check(){

time=`date "+%F %X"`

echo "當(dāng)前時(shí)間:$time"

ip=$(ip a |grep inet |grep "scope global dynamic"|awk -F"/" '{print $1}' |awk '{print $2}')

ping -w1 -c1 www.baidu.com &>/dev/null

if [[ $? -ne 0 ]];then

echo_failure || echo "網(wǎng)絡(luò)異常,請檢查"

else

echo_success && echo "網(wǎng)絡(luò)正常 當(dāng)前IP:$ip"

fi

yum repolist &>/dev/null

if [[ $? -ne 0 ]];then

echo_failure || echo "yum異常,請檢查"

fi

}

function down(){

yum install -y wget &>/dev/null

w=`echo "$1" |tr -d '\n' |od -An -tx1|tr ' ' %`

data=$(curl -s "https://image.baidu.com/search/index?tn=baiduimage&word=$w")

echo $data | grep -P -o "https://ss.*?.jpg" | sort -n -r |uniq >> $2/url2.txt

a=0

while read line

do

sleep 1

code=$(curl -I "$line" 2>/dev/null)

if [ ${code:9:3} -eq 200 ];then

wget -O $2/$1${a}.jpg $line &>/dev/null

echo "下載完成 $line"

else

echo "無效資源 $line"

fi

let a++

done <$2/url2.txt

echo "全部下載完成,下載資源$a個(gè)"

return 200

}

function clea(){

echo "正在打包,請稍后"

sleep 2

tar cvzf image.tar.gz $1

rm -rf $1/url2.txt

}

function main(){

check

down $1 $2

if [[ $? -eq 200 ]];then

clea $2

return 100

else

echo "下載異常,正在清理環(huán)境"

rm -rf $2

return 101

fi

}

clear

echo -e "本程序功能為獲取圖片: 快樂你我他\n程序設(shè)計(jì)腳本測

sleep 1

read -p "請輸入要爬取的圖片關(guān)鍵字,默認(rèn)為中國): " words

read -p "請輸入資源存放路徑,默認(rèn)為 /tmp/image : " path

if [ -z $words ];then

words="中國"

fi

if [ -z $path ];then

path='/tmp/image'

mkdir /tmp/image

fi

main $words $path

if [ $? -eq 100 ];then

echo "程序退出"

else

echo "程序異常退出"

fi

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“shell腳本如何實(shí)現(xiàn)獲取圖片”這篇文章對大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI