代码: 全选
#!/bin/bash
#weather.sh
#使用方法 weather.sh 城市,默认城市为上海
if [ -n "$1" ] #判断输入是否为空
then
place="$1"
else
place="北京"
fi
rm -f index.shtml
wget -q http://weather.sina.com.cn/text/index.shtml
iconv -f GB2312 -t UTF-8 index.shtml > index.shtml1
ifzhixia=$(grep "$place" -c index.shtml1)
if [ "$ifzhixia" = 2 ]
then
cat index.shtml | grep "$place" -A 3 |sed '1d' | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
elif [ "$ifzhixia" = 1 ]
then
cat index.shtml | grep "$place" -A 3 | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
else
echo "没有该城市的天气讯息!"
#rm -f index.shtml .weathertemp .weathertemp2 index.shtml1
exit 0
fi
condition="天气状况: "
wind="风向风力: "
tempr="最高温度: "
placetitle="城市:"
echo "$placetitle">.weathertemp
echo "$condition" >> .weathertemp
echo "$wind" >> .weathertemp
echo "$tempr" >> .weathertemp
echo -e "$place今天的天气情况为:\n"
paste .weathertemp .weathertemp2
rm -f index.shtml .weathertemp .weathertemp2 index.shtml1
exit 0
第二,那个用wget下载的链接是如何做的?
第三,在下载了网站之后,对那个搜索所需信息的两条代码不解。
这个脚本我试着运行过,但无论输入任何城市得到的都是“没有该城市的天气讯息”。
纯新手,求勿鄙视,谢谢了啊!!
