ITPub博客

首页 > 云计算 > Openstack > 云计算教程学习路线视频源码课件:shell脚本实现获取图片

云计算教程学习路线视频源码课件:shell脚本实现获取图片

原创 Openstack 作者:千锋云计算 时间:2020-03-09 14:32:09 0 删除 编辑

在云计算蓬勃发展的今天,与其在家闲着,不如立即开始学习,现在开始,千锋HTML5、UI交互设计、PHP、Java+云数据、大数据开发、VR/AR/Unity游戏开发、Python人工智能、Linux云计算、全栈软件测试视频教程免费送!领取方式在下方留言即可,希望可以帮助你在“逆境”中成长,从容开启新的一年。下面千锋给大家讲解一下:shell脚本实现获取图片。

#!/usr/bin/bash

. /etc/init.d/functions

function check(){

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

echo "当前时间:$time"

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

ping -w1 -c1 &>/dev/null

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

echo_failure || echo "网络异常,请检查"

else

echo_success && echo "网络正常 当前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个"

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 "下载异常,正在清理环境"

rm -rf $2

return 101

fi

}

clear

echo -e "本程序功能为获取图片: 图片\n礼貌爬取,快乐你我他\n程序设计目的:shel脚本#!/usr/bin/bash

. /etc/init.d/functions

function check(){

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

echo "当前时间:$time"

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

ping -w1 -c1 &>/dev/null

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

echo_failure || echo "网络异常,请检查"

else

echo_success && echo "网络正常 当前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个"

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 "下载异常,正在清理环境"

rm -rf $2

return 101

fi

}

clear

echo -e "本程序功能为获取图片: 快乐你我他\n程序设计脚本测

sleep 1

read -p "请输入要爬取的图片关键字,默认为中国): " words

read -p "请输入资源存放路径,默认为 /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


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69916964/viewspace-2679183/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-18

  • 博文量
    933
  • 访问量
    613494