【发布时间】:2016-12-28 11:13:06
【问题描述】:
我下载了我的 Foursquare 数据,它采用 KML 格式。我正在使用 Python 将其解析为 XML 文件,但无法弄清楚如何获取封闭标签和封闭描述标签之间的文本。 (这是我签到时输入的文本,在下面的示例中是“终于到了!与 Sonya 和 co”,但还有一个连字符)。
这是数据外观的示例。
<Placemark>
<name>hummus grill</name>
<description>@<a href="https://foursquare.com/v/hummus-grill/4aab4f71f964a520625920e3">hummus grill</a>- FINALLY HERE!! With Sonya and co</description>
<updated>Tue, 24 Jan 12 17:14:00 +0000</updated>
<published>Tue, 24 Jan 12 17:14:00 +0000</published>
<visibility>1</visibility>
<Point>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>-75.20104383595685,39.9528387056977</coordinates>
</Point>
</Placemark>
到目前为止,我已经能够获取纬度/经度、发布日期、名称以及与代码类似的链接:
latitudes = []
longitudes = []
for d in dom.getElementsByTagName('coordinates'):
#Break them up into latitude and longitude
coords = d.firstChild.data.split(',')
longitudes.append(float(coords[0]))
latitudes.append(float(coords[1]))
我试过了(下面是数据开头有这个header的东西,还没想好怎么处理)
for d in dom.getElementsByTagName('description'):
description.append(d.firstChild.data.encode('utf-8'))
<?xml version="1.0" encoding="UTF-8"?>
<kml><Folder><name>foursquare checkin history </name><description>foursquare checkin history </description>:
然后通过这个 d.firstChild.nextSibling.firstChild.data.encode('utf-8') 访问它,但它只是给了我“鹰嘴豆泥烧烤”,我假设它是 a 之间的文本标签(而不是来自名称标签)。
【问题讨论】: