if "" == text:
raise RuntimeError("解析的内容不能为空")
docu = xml.dom.minidom.parseString(text)
root = docu.documentElement
getNodeText(root)
def getNodeText(ele):
if ele.nodeType == xml.dom.minidom.Node.ELEMENT_NODE:
for e in ele.childNodes:
getNodeText(e)
elif ele.nodeType in (xml.dom.minidom.Node.TEXT_NODE,xml.dom.minidom.Node.CDATA_SECTION_NODE):
print(ele.nodeValue.strip())
<CityWeatherResponse>
<status>success</status>
<date>2014-04-27</date>
<results>
<currentCity>双牌</currentCity>
<weather_data>
<date>周六(实时:16℃)</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/yin.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/yin.png
</nightPictureUrl>
<weather>阴</weather>
<wind>北风微风</wind>
<temperature>15℃</temperature>
<date>周日</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多云</weather>
<wind>北风微风</wind>
<temperature>20 ~ 15℃</temperature>
<date>周一</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多云</weather>
<wind>北风微风</wind>
<temperature>22 ~ 15℃</temperature>
<date>周二</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/zhenyu.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/zhenyu.png
</nightPictureUrl>
<weather>阵雨</weather>
<wind>北风微风</wind>
<temperature>20 ~ 15℃</temperature>
</weather_data>
<currentCity>长沙</currentCity>
<weather_data>
<date>周六(实时:16℃)</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/zhenyu.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/zhenyu.png
</nightPictureUrl>
<weather>阵雨</weather>
<wind>微风</wind>
<temperature>15℃</temperature>
<date>周日</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多云</weather>
<wind>微风</wind>
<temperature>21 ~ 15℃</temperature>
<date>周一</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多云</weather>
<wind>微风</wind>
<temperature>24 ~ 15℃</temperature>
<date>周二</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多云</weather>
<wind>北风微风</wind>
<temperature>24 ~ 14℃</temperature>
</weather_data>
</results>
</CityWeatherResponse>
375



被折叠的 条评论
为什么被折叠?



