Extract Data (likes) From JSON API Using Python
I want to pull the number of likes for my project. Here's my code: import facepy from facepy import GraphAPI from bs4 import BeautifulSoup import json access = 'CAACEdEose0cBAE3I
Solution 1:
As this is a generator, there's no good way to get a specific element. You can either iterate over it and check for each element if it's the one you're looking for, or, if you will need more than one element from it, convert it into a dictionary.
This is one way to convert it:
new_dictionary = {}
for name, value in datas:
new_dictionary[name] = value
With this you could then get likes with:
likes = new_dictionary['likes']
Or if you only want to get 'items' from it:
for name, value in datas:
if name == 'likes':
likes = value
Solution 2:
import facepy
from facepy import GraphAPI
from bs4 import BeautifulSoup
import json
access = 'CAACEdEose0cBAE3IL99IreDeAfqaVZBOje8ZCqIhf6tPaf7HsPF3J9DYRWi3YuSTf0HXQwr2LMAgczDBWBSDNFzHrEjxzkBQ9hbZCYC1fB2z1qyHs5BeAZCV3zyU8JhEcbSiiB5Bf73gZAfQ1rUa2pdx9U24dUZCX0qMDzvXHLHV9jPRiZBByB2b2uEHGk22M4ZD'
graph = GraphAPI(access)
page_id= 'walkers'
datas= graph.get(page_id+'/', page=True, retry=5)
likes = datas['likes']
print likes
Post a Comment for "Extract Data (likes) From JSON API Using Python"