2

I was trying to develop a python script for my friend, which would take a link of a public album and count the like and comment numbers of every photo with "requests" module. This is the code of my script

import re
import requests

def get_page(url):
    r = requests.get(url)
    content = r.text.encode('utf-8', 'ignore')
    return content


if __name__ == "__main__":
    url = 'https://www.facebook.com/media/set/?set=a.460132914032627.102894.316378325074754&type=1'
    content = get_page(url)
    content = content.replace("\n", '')

    chehara = "(\d+) likes and (\d+) comments"
    cpattern = re.compile(chehara)
    result = re.findall(cpattern, content)
    for jinish in result:
        print "likes "+ jinish[0] + " comments " + jinish [1]

But the problem here is, it only parses the likes and comments for the first 28 photos, and not more, what is the problem? Can somebody please help?

[Edit: the module "request" just loads the web page, which is, the variable content contains the full html source of the facebook web page of the linked album]

mathbender
  • 23
  • 5
  • I don´t have access to the requests-module. Can not provide an example of what the variable content includes? – theAlse Dec 18 '12 at 08:02
  • The variable content is complete html source of the facebook page. – mathbender Dec 18 '12 at 08:09
  • you might want to try [pyfacebook](https://github.com/sciyoshi/pyfacebook/) or [pyfb](https://github.com/jmg/pyfb) –  Dec 18 '12 at 11:38

2 Answers2

0

use the facebook graph api:

For Albums its documented here:

https://developers.facebook.com/docs/reference/api/album/

Use the limit attribute for testing since its rather slow:

http://graph.facebook.com/460132914032627/photos/?limit=10

EDIT

i just realized that the like_count is not part of the json, you may have to use fql for that

Christian Thieme
  • 1,114
  • 6
  • 6
0

If you want to see the next page you need to add the after attribute to your request like in this URL:

https://graph.facebook.com/albumID/photos?fields=likes.summary(true),comments.summary(true)&after=XXXXXX&access_token=XXXXXX

You could take a look at this JavaScript project for reference.

Community
  • 1
  • 1
Loïc Joachim
  • 89
  • 1
  • 8