python解析xml字符串

时间:2012-10-23 02:34:19

标签: python xml parsing elementtree

我正在尝试解析网站上的数据而无法打印数据。

import xml.etree.ElementTree as ET
from urllib import urlopen

link = urlopen('http://weather.aero/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KSFO&hoursBeforeNow=1')

tree = ET.parse(link)
root = tree.getroot()

data = root.findall('data/metar')
for metar in data:
    print metar.find('temp_c').text

1 个答案:

答案 0 :(得分:2)

区分大小写:

data = root.findall('data/METAR')