Python查询天气小程序
来源:互联网 发布:2017淘宝黑科技 编辑:程序博客网 时间:2024/05/21 09:18
输入城市名,打印查询结果
#!/usr/bin/env python#encoding:utf-8#By eathingsimport urllibimport urllib2import refrom xml.dom.minidom import parseStringclass Weather:def __init__(self):self.url = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx/getWeatherbyCityName"def get_weather(self,thecityname):url = self.url + "?thecityname=" + thecitynameresult = urllib2.urlopen(url).read()dom = parseString(result)strings = dom.getElementsByTagName("string")temperature_of_today = self.getText(strings[5].childNodes)weather_of_today = self.getText(strings[6].childNodes)temperature_of_tomorrow = self.getText(strings[12].childNodes)weather_of_tomorrow = self.getText(strings[13].childNodes)weather_tips = self.getText(strings[11].childNodes)weatherStr = u"今明两天的天气状况是:\n %s %s; %s %s;\n"%\(weather_of_today,temperature_of_today,weather_of_tomorrow,temperature_of_tomorrow)weatherTips = u"友情提示:\n%s" %weather_tips print weatherStrprint weatherTipsdef getText(self,nodelist):"""获取所有的"""rc=""for node in nodelist:if node.nodeType==node.TEXT_NODE:rc=rc+node.datareturn rcweath = Weather()print "输入城市名,显示查询结果"thecityname = raw_input()weath.get_weather(thecityname)
0 0
- Python查询天气小程序
- Python之查询天气小程序
- python 查询小程序
- 微信小程序入门级项目---天气查询小程序
- 【Python】 天气查询
- python天气查询
- python实现查询天气
- Python Flask 天气查询
- python查询天气
- 微信小程序-天气查询demo
- 【Python】实现一个天气查询
- python 查询天气(输入城市名,输出天气)
- python查询全国主要天气代码
- Python调用百度API之天气查询
- 用python 实现自主查询实时天气
- python实例3-天气小模块
- python 自动获取天气程序(V1)
- python项目之 天气程序 带GUI
- cocos2d-x在eclipse上搭建开发环境(全网最标准方法)
- HDU 2289 Cup 数学+二分
- DRBD安装测试过程记录(二)
- cocos2dx快捷创建项目脚本
- Android APP如何防止二次打包
- Python查询天气小程序
- UML之协作图
- Cocos2d-x Scene生命周期 pushScene和replaceScene
- Cracking the coding interview--Q4.8
- NYOJ 107 A Famous ICPC Team
- Cocos2dx-游戏开发中不同的坐标系,cocos2dx锚点
- 超简单的数码相框制作
- “舍友勾搭上我爸还怀孕了!
- linux lib 动态库