Flickr favorites extraction

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 photos?

Note: it works through this testing page: http://www.flickr.com/services/api/explore/?method=flickr.favorites.getPublicList

+3
source share
1 answer

The result is correct - according to the URL you specify, the XML nodes are empty (plus / minus newlines and whitespace, apparently). favs.textwill return the contents, but what you are looking for is in the attributes. Try the following:

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')]
+4
source

Source: https://habr.com/ru/post/1753211/


All Articles