shell脚本抓取网页信息

利用shell脚本分析网站数据

# define url
time=$(date +%F)
mtime=$(date +%T)
file=/abc/shell/abc/abc_$time.log
http=https://abc.com/abc/abc.do
key='tender_sum'

log_file=/abc/shell/abc/remind.log
check_log=/abc/shell/abc/check.log

function Mail(){
    mail -s "抓取成功" 88888888@qq.com < $log_file
}

curl -d "user=abc&password=123" $http > $file 
echo $?

#抓第一段数组

name=`awk -F ',' '{print $13":"$32}' $file | awk -F ':' '{print $4}'`
echo "name=$name"

tender_sum=`awk -F ',' '{print $13":"$32}' $file | awk -F ':' '{print $2}'`
echo "tender_sum=$tender_sum"

borrow_sum=`awk -F 'borrow_sum' '{print $2}' $file | awk -F '[: ,]' '{print $2}'`
echo "borrow_sum=$borrow_sum"
flag=1
#如果有一个名字跟他相等,说明没有新的内容
for title in `cat project_title.log`
    do
        if [ $name == $title ]
            then
                flag=0
        fi
    done

#出现了新的内容,判断是否满足条件,是则发邮件通知,并且将标题写入project_title.log
if [ $flag == 1 ]
    then
        if [ $tender_sum == $borrow_sum ]
            then
                echo "内容$name已经更新成功,请登录网站查看^_^" > $log_file
                Mail
                echo $name >> project_title.log
            else
                echo "内容$name更新进度:已更新-- $tender_sum --$mtime--" >> $check_log 
        fi
    else
        echo "没有新的内容" >> $check_log
fi
    

 

posted @ 2017-02-07 10:52  kangjie  阅读(5743)  评论(0编辑  收藏  举报