检索 flickr 收藏夹

发布于 2024-09-08 10:18:54 字数 530 浏览 2 评论 0原文

我无法让它工作...可能是什么问题?

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

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?

Note: It does work via this testing page: http://www.flickr.com/services/api/explore/?method=flickr.favorites.getPublicList

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-09-15 10:18:54

结果是正确的——根据您提供的 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')]

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')

Result:

'445267544'
'3334987037'

Or for all child nodes, starting from the root:

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

Result:

[('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')]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文