【问题标题】:python parse xml stringpython解析xml字符串
【发布时间】:2012-10-23 02:34:18
【问题描述】:

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

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)字符串是有条件的基于天气,所以它总是在变化。 2) 它不像 temp_c 和 temp_f,所有的天空条件都在一个字段名称中。

标签: python xml parsing elementtree


【解决方案1】:

区分大小写:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多