到目前为止,这是我的代码,我想使用从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 " / >
任何人都可以帮助打印出这些信息,特别是获取标签变量。在任何地方我都注释掉了一个print语句,变量工作正常。
在此先感谢您的帮助,我非常感谢它,因为我是python的新手
答案 0 :(得分:1)
您需要内容,node_info
只是Response对象,您需要调用.content或.text来查看返回的内容:
print node_info.content