【发布时间】:2012-11-04 04:26:34
【问题描述】:
我有一些快餐店的 OSM 数据,我使用 Xapi 检索到,here 是一些示例结果:
<osm version="0.6" generator="Osmosis SNAPSHOT-r26564">
<node id="486275964" version="4" timestamp="2010-05-03T08:21:42Z" uid="12055" user="aude" changeset="4592597" lat="38.8959533" lon="-77.0212458">
<tag k="name" v="Potato Valley Cafe"/>
<tag k="amenity" v="fast_food"/>
</node>
<node id="486275966" version="4" timestamp="2010-08-06T16:44:13Z" uid="207745" user="NE2" changeset="5418228" lat="38.8959399" lon="-77.0196338">
<tag k="cuisine" v="burger"/>
<tag k="name" v="McDonald's"/>
<tag k="amenity" v="fast_food"/>
</node>
<node id="612190923" version="1" timestamp="2010-01-12T14:01:27Z" uid="111209" user="cov" changeset="3603297" lat="38.893683" lon="-77.0292732">
<tag k="level" v="-1"/>
<tag k="cuisine" v="sandwich"/>
<tag k="name" v="Quizno's"/>
<tag k="amenity" v="fast_food"/>
</node>
</osm>
<!--corrected indentation-->
我正在尝试在 python 中使用 BeautifulSoup 来从中提取经纬度、名称和美食。这段代码我可以得到经纬度没有问题:
soup = BeautifulSoup(results)
takeaways = soup.findAll('node')
for eachtakeaway in takeaways:
longitude = str(eachtakeaway['lon'])
lattitude = str(eachtakeaway['lat'])
但我不知道名字:
name = str(eachtakeaway['name'])
这会引发错误:
TypeError: 'NoneType' object is not callable
你能告诉我该怎么做吗?谢谢。
【问题讨论】:
标签: python xml beautifulsoup openstreetmap