检索 flickr 收藏夹 [英] Retrieving flickr favorites
问题描述
我无法让它工作......可能是什么问题?
I can't get this to work... what could be the problem?
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'
我最喜欢的照片在哪里?
Where are my favorite photo's?
注意:它确实通过这个测试页面起作用:http://www.flickr.com/services/api/explore/?method=flickr.favorites.getPublicList
Note: It does work via this testing page: http://www.flickr.com/services/api/explore/?method=flickr.favorites.getPublicList
推荐答案
结果是正确的——根据您提供的 URL,XML 节点是空的(显然加/减换行符和空格字符).favs.text
将返回内容,但您要查找的是属性.试试这个:
The result is correct -- as per the URL you gave, the XML nodes are empty (plus/minus newline and whitespace characters, apparently). favs.text
would return the content, but what you're looking for is in the attributes. Try this:
for photo in favs.find('photos').findall('photo'):
print photo.get('id')
结果:
'445267544'
'3334987037'
或者对于所有子节点,从根开始:
Or for all child nodes, starting from the root:
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')]
这篇关于检索 flickr 收藏夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!