kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.45k stars 633 forks source link

Issues in counting reactions and comments #458

Open jha46 opened 3 years ago

jha46 commented 3 years ago

Hello. I faced several problems while using this package for scraping public pages.

  1. 'likes' does not count total reactions, It counts a reaction 'like'. According to the post example in this page, it seems that it intends total reactions.
  2. 'Reactions' returns none (set extra_info=True).
  3. 'comment' does not take replies on comments into account. It only counts original comments. Any help would be appreciated. Thank you so much!
neon-ninja commented 3 years ago

Hi,

Try pass cookies as per the readme. The reason being, that Facebook shows different counts of reactions depending on whether you're logged in or not - just likes if you're not, or actual total if you are. Similarly for the comment count, with count of top level comments vs count of comments + replies. Extracting reactions also likely require a login. The total count of reactions can be found in the reaction_count key.

This sample code:

post = next(get_posts(post_urls=[4451740514910367], cookies="cookies.json", options={"comments": True, "reactions": True, "progress": True}))
count = 0
for comment in post["comments_full"]:
    count += 1 + len(comment["replies"])
print(f'''Comments: {post["comments"]}
Likes: {post["likes"]}
Reactions: {post["reaction_count"]} ({post["reactions"]})
len(comments): {len(post["comments_full"])}
len(comments+replies): {count}''')

outputs:

Comments: 57
Likes: 392
Reactions: 459 ({'like': 392, 'love': 56, 'wow': 4, 'care': 6, 'sad': 1})
len(comments): 26
len(comments+replies): 51
jha46 commented 3 years ago

It works. Thank you so much.