2012-12-18 23 views
2

我試圖爲我的朋友開發一個python腳本,該腳本將採用公共相冊的鏈接,並用「requests」模塊計算每張照片的相似和評論編號。這是我的腳本從facebook相冊中獲取相似數量

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] 

的代碼,但這裏的問題是,它只是解析喜好和意見的第28張照片,而不是多,是什麼問題?有人可以幫忙嗎?

[編輯:模塊「請求」只是加載網頁,其中,可變內容包含facebook的網頁鏈接的專輯的完整的HTML源]

+0

我無法訪問請求模塊。無法提供變量內容包含的示例? – theAlse

+0

變量內容是facebook頁面的完整html源代碼。 – mathbender

+0

你可能想嘗試[pyfacebook](https://github.com/sciyoshi/pyfacebook/)或[pyfb](https://github.com/jmg/pyfb) – 2012-12-18 11:38:08

回答

0

如果你想看到你需要添加下一個頁面在您的請求屬性後,如在此URL:

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

你可以看看這個JavaScript project作爲參考。

相關問題