一个天气预报的脚本
发表于 : 2007-09-04 14:18
闲来无事,写了天气预报的脚本,与大家分享。
本人菜鸟,如有任何问题或建议,欢迎指正。谢谢。
数据来自 http://weather.265.com
20080524更新,感谢bthink发现265的改版消息。
本人菜鸟,如有任何问题或建议,欢迎指正。谢谢。
数据来自 http://weather.265.com
20080524更新,感谢bthink发现265的改版消息。
就是shell。vim7 写了:tar.. - -!!
用什么写的? shell?
ofewiofewo 写了:呵呵,学习,填了几个city参数
广州: 25℃~29℃ 下午:阴转多云,阵雨;晚上:阴转多云,小雨
漳州: 24℃~29℃ 下午:阴转多云,小阵雨;晚上:阴转多云,有雨
丹东: 17℃~28℃ 下午:晴转多云;晚上:晴转多云
代码: 全选
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib, re, sys
def getcitycode():
conn=urllib.urlopen("http://weather.265.com/get_weather.php?action=get_city")
citysrc=conn.read().decode("gbk").encode("utf8")
conn.close()
citycode=re.findall('[0-9]{5}', citysrc)[0]
return citycode
def getweather(code):
url="http://weather.265.com/weather/"+code+".htm"
conn=urllib.urlopen(url)
weasrc=conn.read().decode("gbk").encode("utf8")
conn.close()
wea=re.findall('show_weather\("(.*)"\)', weasrc)[0].split("'")
weather=[item for item in wea if item !="," and ")" not in item and "(" not in item]
city=wea[0].split('"')[0]
option=[u'今天:',u'上午:',u'下午:',u'晚上:',u'明天:',u'上午:',u'下午:',u'晚上:']
#print "\n".join(weather)
index=0
print u'城市:',city
while index < (len(option)):
print option[index],weather[index]
index=index+1
if __name__=='__main__':
try:
code=sys.argv[1]
except:
code=getcitycode()
getweather(code)
kyowu 写了:是这样用么?
解压后,
chmod -x weather
./weather
为什么提示
bash: ./weather:Permission denied
???
代码: 全选
chmod u+x weather
在文本中挑出有含有'wid_265='的那行,再剔除kyowu 写了:grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'
这句话如何解析呀?
kyowu 写了:是这样用么?
解压后,
chmod -x weather
./weather
为什么提示
bash: ./weather:Permission denied
???