LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: sipingal

今天写了个从腾讯网站抓取天气信息的脚本

[复制链接]
发表于 2005-12-14 16:45:44 | 显示全部楼层
Post by ajinn
弱弱的问一下,怎样查询到自己城市的代码

随便进一个城市的天气预报页面后
再看一个html源码就行了
不过我已经列出qq支持的所有城市
回复 支持 反对

使用道具 举报

发表于 2005-12-15 15:27:51 | 显示全部楼层
我用在torsmo的从yahoo网站的weather:
weather.sh
  1. #!/bin/bash
  2. city="QingDao"
  3. link=CHXX0110_c.html?force_units=1
  4. file=/tmp/weather.txt
  5. location=http://weather.yahoo.com/forecast/$link
  6. lynx -accept_all_cookies -dump $location > $file
  7. begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`
  8. end=`expr $begin + 40`
  9. head -n $end $file > tmp.t
  10. tail -n 41 tmp.t > $file
  11. case $1 in
  12.         Today) head -n 6 $file | sed '3d' ;;
  13.         Tomorrow)
  14.         begin=`cat -n $file | grep 'Today Tomorrow' | cut -d ' ' -f5`
  15.         end=`cat -n $file | grep 'Extended' | cut -d ' ' -f5`
  16.         num=`expr $end - $begin - 1`
  17.         end2=`expr $begin + 7`
  18.         head -n $end2 $file > tmp.t
  19.         tail -n 3 tmp.t | sed 's/sky/\n sky/' | sed '4d' ;;
  20.         *) exit ;;
  21. esac
  22. rm tmp.t
  23. rm $file
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-12-15 17:19:49 | 显示全部楼层
偶是从人民网wget天气的。
回复 支持 反对

使用道具 举报

发表于 2005-12-15 18:53:23 | 显示全部楼层
其实新浪的更简单
基本是可以直接awk的
一个页面包含了全国的天气
http://weather.sina.com.cn/image ... ap/wholeNation.html
回复 支持 反对

使用道具 举报

发表于 2005-12-15 19:45:51 | 显示全部楼层
怎样能把脚本的输出直接作为roottail的输入
回复 支持 反对

使用道具 举报

发表于 2005-12-15 21:56:16 | 显示全部楼层
Post by threedot
弱弱的问一下,root-tail用哪个中文字体啊?我的不能显示中文

用iconv转成UTF8
回复 支持 反对

使用道具 举报

发表于 2005-12-18 18:24:25 | 显示全部楼层
Post by cyc
用iconv转成UTF8

转过了,还是不行.我都把locale改为UTF8了.
提示
Missing charsets in String to FontSet conversion (GBK-0)
回复 支持 反对

使用道具 举报

发表于 2006-2-10 15:19:12 | 显示全部楼层
使用python改写的一个:

  1. #! /usr/bin/python
  2. # -*- coding: cp936 -*-
  3. import urllib,re
  4. code=125
  5. if __name__=="__main__":
  6.         response = urllib.urlopen("http://weather.news.qq.com/inc/ss%s.htm" %code)
  7.         result=re.findall(r'align="center">([^<\s]+)[\s]*</td>',response.read())
  8.         print '天  气: %s\n温  度: %s\n风  力: %s\n空  气: %s\n紫外线: %s' %(result[0],result[1],result[2],result[4],result[3])
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-2-17 15:26:04 | 显示全部楼层
楼主的桌面太漂亮啦!不知是怎么弄出来的呢?
回复 支持 反对

使用道具 举报

发表于 2006-3-4 16:50:28 | 显示全部楼层
[php]#!/bin/bash

cd /tmp
wget http://weather.news.qq.com/inc/ss211.htm

clear

#城市
tmp_city=$(cat ss211.htm|grep '211'|sed 's/^.*\">//g'|sed 's/<.*$//g')

#天气
tmp_tianqi=$(cat ss211.htm|grep '117'|sed 's/^.*\">//g'|sed 's/<.*$//g')

#温度
tmp_wendu=$(cat ss211.htm|grep '℃'|sed 's/^.*\">//g')

#风力
tmp_feng=$(cat ss211.htm|sed -n '26p'|sed 's/^.*\">//g'|sed 's/<.*$//g')

#紫外线
tmp_ziwai=$(cat ss211.htm|sed -n '33p'|sed 's/^.*\">//g'|sed 's/<.*$//g')

#空气
tmp_kongqi=$(cat ss211.htm|sed -n '38p'|sed 's/^.*\">//g'|sed 's/<.*$//g')


rm -f ss211.htm

echo -e   "\n\n"
echo -e   "  \t\t\t城市   :         $tmp_city"
echo
echo -e   "    \t\t\t天气   :         $tmp_tianqi"
echo
echo -e   "    \t\t\t温度   :         $tmp_wendu"
echo
echo -e   "    \t\t\t风力   :         $tmp_feng"
echo
echo -e   "    \t\t\t紫外线 :         $tmp_ziwai"
echo
echo -e   "    \t\t\t空气   :         $tmp_kongqi"

[/php]


我的好像一点技术含量都没   ,  昏  !
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表