Extract data (likes) from JSON API using Python -


i want pull number of likes project.

here's code:

import facepy facepy import graphapi bs4 import beautifulsoup import json access = 'caacedeose0cbae3il99iredeafqavzboje8zcqihf6tpaf7hspf3j9dyrwi3yustf0hxqwr2lmagczdbwbsdnfzhrejxzkbq9hbzcyc1fb2z1qyhs5beazcv3zyu8jhecbsiib5bf73gzafq1rua2pdx9u24duzcx0qmdzvxhlhv9jprizbbyb2b2uehgk22m4zd' graph = graphapi(access) page_id= 'walkers' datas= graph.get(page_id+'/', page=true, retry=5) data in datas:     print data 

and here's output:

  {     u'category': u'product/service',     u'username': u'walkers',     u'about': u"welcome home of walkers crisps. when comes making brits smile, we\u2019ve got in bag (yeah, went there.) we're here mon-fri, 9am-6pm!",     u'talking_about_count': 3076,     u'description': u'to find out more walkers, visit:\nhttp://twitter.com/walkers_crisps\nhttp://www.youtube.com/walkerscrisps',     u'has_added_app': false,     u'can_post': true,     u'cover': {       u'source': u'https://scontent.xx.fbcdn.net/hphotos-xpt1/t31.0-8/s720x720/11165156_10153204315777649_4115137634691483959_o.jpg',       u'cover_id': u'10153204315777649',       u'offset_x': 0,       u'offset_y': 0,       u'id': u'10153204315777649'     },     u'name': u'walkers',     u'website': u'http://www.walkers.co.uk',     u'link': u'https://www.facebook.com/walkers',     u'likes': 552762,     u'parking': {       u'street': 0,       u'lot': 0,       u'valet': 0     },     u'is_community_page': false,     u'were_here_count': 0,     u'checkins': 0,     u'id': u'53198517648',     u'is_published': true   } 

i want pull number of likes, preferably number. how 1 go doing this?

as generator, there's no good way specific element. can either iterate on , check each element if it's 1 you're looking for, or, if need more 1 element it, convert dictionary.

this 1 way convert it:

new_dictionary = {} name, value in datas:     new_dictionary[name] = value 

with likes with:

likes = new_dictionary['likes'] 

or if want 'items' it:

for name, value in datas:     if name == 'likes':         likes = value 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -