其他分享
首页 > 其他分享> > 检索flickr收藏夹

检索flickr收藏夹

作者:互联网

我无法解决这个问题……可能是什么问题?

import flickrapi

api_key = '1234...'

flickr = flickrapi.FlickrAPI(api_key)
user = '43699959@N02'
favs = flickr.favorites_getPublicList(user_id = user)

>>> favs.items()
[('stat', 'ok')]

>>> favs.text
'\n'

我最喜欢的照片在哪里?

注意:它可以通过以下测试页面正常工作:http://www.flickr.com/services/api/explore/?method=flickr.favorites.getPublicList

解决方法:

结果是正确的-根据您提供的URL,XML节点为空(显然,加/减换行符和空格字符). favs.text将返回内容,但是您要查找的是属性.尝试这个:

for photo in favs.find('photos').findall('photo'):
    print photo.get('id')

结果:

'445267544'
'3334987037'

或对于所有子节点,从根开始:

for elm in favs.getiterator():
    print elm.items()

结果:

[('stat', 'ok')]
[('total', '2'), ('perpage', '100'), ('page', '1'), ('pages', '1')]
[('isfamily', '0'), ('title', 'The Giants of Africa'), ('farm', '1'), ('ispublic', '1'), ('server', '218'), ('isfriend', '0'), ('secret', '992df924aa'), ('owner', '49746597@N00'), ('id', '445267544'), ('date_faved', '1273873654')]
[('isfamily', '0'), ('title', 'Lava Light - Maui, Hawaii'), ('farm', '4'), ('ispublic', '1'), ('server', '3401'), ('isfriend', '0'), ('secret', '2fa1856916'), ('owner', '7765891@N08'), ('id', '3334987037'), ('date_faved', '1273873515')]

标签:api,flickr,python
来源: https://codeday.me/bug/20191106/1999091.html