从 python 中的 osmapi 调用打印出节点信息

Printing out node info from an osmapi call in python

到目前为止,这是我的代码,我想使用从 flickr 图像获得的详细信息,并确定地理位置是否连接到节点。然后我想使用 osmapi 来获取节点信息。

import flickrapi
import osmapi
import overpy
import geopy
from geopy.geocoders import Nominatim
import requests

api_key = "xxxxxxxxxxxxxxxxxxxxx"
secret_api_key = "xxxxxxx"
flickr = flickrapi.FlickrAPI(api_key, secret_api_key)

def obtainImages():

    photo_list = flickr.photos.search(api_key=api_key, accuracy = 15, has_geo=1, per_page = 100, extras = 'tags, url_s')

    for photo in photo_list[0]:

        id = str(photo.attrib['id'])
        tags = (photo.attrib['tags']).encode('utf-8')
        url = str(photo.attrib['url_s'])
        title = (photo.attrib['title']).encode('utf-8')

        photo_location = flickr.photos_geo_getLocation(photo_id=photo.attrib['id'])
        lat = float(photo_location[0][0].attrib['latitude'])
        lon = float(photo_location[0][0].attrib['longitude'])

        geolocator = Nominatim()
        location = geolocator.reverse("{}, {}".format(lat, lon))
        #print(location.raw)
        dict = location.raw
        osmid = dict.get('osm_id', 'default_value_if_null_here')
        osmtype = dict.get('osm_type', 'default_value_if_null_here')
        #print osmid
        #print osmtype

        if(osmtype == 'node'):
            node_info = requests.get("http://api.openstreetmap.org/api/0.6/node/"+ osmid)
            print node_info

obtainImages()

然而,当我 运行 这时,我得到了以下内容

<Response [200]>
<Response [200]>
<Response [200]>
................
................
<Response [200]>

然而我想要得到的是这样的结果:

< node id =" 592637238 " lat =" 47.1675211 " lon =" 9.5089882 "
       version ="2" changeset =" 6628391 "
       user =" phinret " uid =" 135921 "
       timestamp =" 2010 -12 -11 T19:20:16Z " >
   < tag k=" amenity " v=" bar " / >
   < tag k=" name " v=" Black Pearl " / >

任何人都可以帮助打印出这些信息,特别是获取标签变量。在我注释掉打印语句的任何地方,变量工作正常。

在此先感谢您的帮助,非常感谢,因为我是 python

的新手

你需要内容,node_info只是Response对象,你需要调用.content或.text来查看返回的内容:

print node_info.content