【发布时间】:2018-07-15 23:35:16
【问题描述】:
我想处理开放数据,xml存储在这里:
在这个论坛的帮助下,我编写了代码
from lxml import etree
from urllib.request import urlopen
root = etree.parse(urlopen(url)).getroot()
ns = { 'd': 'http://datex2.eu/schema/2/2_0' }
parking_area = root.xpath('//d:parkingAreaStatus', namespaces=ns)
parking_facility = root.xpath('//d:parkingFacilityStatus', namespaces=ns)
for pa in parking_area:
area_ref = pa.find('d:parkingAreaReference', ns)
ParkingspaceList.append(str((area_ref.get('id'))))
for pf in parking_facility:
facility_ref = pf.find('d:parkingFacilityReference', ns)
ParkingspaceList.append(str((facility_ref.get('id'))))
这似乎适用于“pa”,但对于“pf”我收到一条失败消息:
ParkingspaceList.append(str((facility_ref.get('id')))) AttributeError: 'NoneType' 对象没有属性 'get'
有什么建议吗?
最好的问候
TR
【问题讨论】:
标签: python xml parsing lxml elementtree