[SHELL SCRIPT] LINUX正则表达式 课堂作业 获取PM2.5天气信息
程序员文章站
2022-07-14 15:43:02
...
因特网,你好强大!
#!/bin/bash
rm result.txt
rm beijing*
wget http://www.pm25s.com/beijing.html
if [ $? -ne 0 ]; then
exit 1
fi
echo "<INFO> DOWNLOAD PM_2_5 INFO FINISHED"
DATE=$(grep -oP "(?<=数据更新时间:).*(?=</div>)" ./beijing.html)
echo "<INFO> DATE MESSAGE: ${DATE}"
SITE_LIST_T=$(grep -oP '<span class=\"site\">[^0-9^/]*</span>' ./beijing.html |
grep -oP '(?<=<span class=\"site\">).*(?=</span>)')
PM_2_5_LIST_T=$(grep -oP '<span class=\"aqis\">[0-9\-\.]*</span>' ./beijing.html |
grep -oP '(?<=<span class=\"aqis\">).*(?=</span>)')
_site_size=0
_pm_size=0
for SITE in $SITE_LIST_T
do
SITE_LIST[$_site_size]=$SITE
let "_site_size+=1"
done
for PM in $PM_2_5_LIST_T
do
PM_2_5_LIST[$_pm_size]=$PM
let "_pm_size+=1"
done
echo ""
echo "PM_LIST_LENGTH: ${_pm_size} SITE_LIST_LENGTH: ${_site_size}"
echo ""
_site=0
for ((_index=0; _index<${_pm_size};_index+=7))
do
echo "${DATE} ${SITE_LIST[${_site}]} ${PM_2_5_LIST[${_index}]}" >> result.txt
let "_site+=1"
if [ $_site -eq ${_site_size} ]; then
break
fi
done
cat result.txt
上一篇: hadoop学习(day01)-环境搭建
下一篇: Hadoop学习笔记(1)-环境搭建