Рет қаралды 8,409
##Python code for this video
import json
from facebook_scraper import get_posts, set_noscript
from facebook_scraper import get_group_info
ginfo = get_group_info("VenomousAndOtherSnakesOfSiam")
print(ginfo['id'])
#479127595592229
We need to login Facebook with this account in a browser before running the code.
listposts=[]
#for post in get_posts("nintendo", pages=2):
posts = get_posts(post_urls=[" / 1874763812695260 "," / 1875124055992569 "], credentials=('FB_ACCOUNT@gmail.com','FB_PASSWORD'), options={"comments":True})
for post in posts:
print post on the screen
print(json.dumps(post,indent=2, default=str))
for x in post:
print(x, post[x])
print json object to file one object/post per line
with open('fb.json', 'a', encoding='utf-8') as f:
json.dump(post, f, ensure_ascii=False, default=str)
f.write("
")
print(post['post_text'])
for cmt in post['comments_full']:
print(cmt['commenter_name']," : ", cmt['comment_text'].replace("
",""))