2

我正在尝试从网站解析数据,但无法打印数据。

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
4

1 回答 1

2

它区分大小写:

data = root.findall('data/METAR')
于 2012-10-23T02:38:13.937 回答