python3获取天气信息
2014-08-30 16:44
357 查看
通过对http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 的调用,获取天气信息
#coding:utf-8
import urllib.parse
import urllib.request
from xml.dom.minidom import parseString
url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName"
values = {"theCityName":u"承德"}
data = urllib.parse.urlencode(values).encode(encoding='UTF8')
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read().decode("utf8")
dom = parseString(the_page)
string = dom.getElementsByTagName("string")
for s in string:
try:
data = s.childNodes[0].data
print(data)
except IndexError as e:
next运行结果:
#coding:utf-8
import urllib.parse
import urllib.request
from xml.dom.minidom import parseString
url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName"
values = {"theCityName":u"承德"}
data = urllib.parse.urlencode(values).encode(encoding='UTF8')
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read().decode("utf8")
dom = parseString(the_page)
string = dom.getElementsByTagName("string")
for s in string:
try:
data = s.childNodes[0].data
print(data)
except IndexError as e:
next运行结果:
相关文章推荐
- 用python+selenium从百度获取本地明日的天气信息并根据温度情况邮件提醒
- 用python+selenium从百度获取本地明日的天气信息并根据温度情况设置提醒
- Python实战-天气预报项目-获取天气信息
- 树莓派使用Python3获取天气信息
- [Python高效编程] - 获取天气信息并使用迭代for输出
- Python网络编程 获取页面中的天气信息
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
- python获取天气信息写入原有的excel文档
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
- Python3:获取天气信息
- python实现获取天气信息后自动登录邮箱发送到指定邮件联系人
- python爬虫获取全国天气信息
- 用python调用中国天气网API获取各大城市的天气信息
- python调用中国天气网的公用API获取天气信息
- python获取天气信息,给指定用户发送邮件
- Android模拟器访问google网站获取天气信息时,出现 java.net.UnknownHostException: www.google.com 错误
- 如何获取天气信息
- WP7通过WebService天气服务获取天气信息
- python获取本地位置和天气
- Python利用系统命令获取文件(夹)信息以及Python对Excel的简单操作