Scrape Facebook Comments

In the previous article, I explained you how to scrape posts from a Facebook page. And I have shown you how to create a FAcebook graph API in order to gather public Data. http://dihiainfos.blogspot.com/2017/11/scrape-facebook-posts-data-scientists.html

In this artcile, I'll explain you how to retrieve the different comments published in a facebook page. (you're not obliged to be an admin of the page, or to be a member of this page)=> it's public

So folow me...

You should know that to get comments, you must create a facebook graph API , if you have created it as I shown you last time you can use it directely. Else, you should create one, refer you to this article: http://dihiainfos.blogspot.com/2017/11/scrape-facebook-posts-data-scientists.html (Create a Graph API)

To get the list of comments related to a specified post, you should write this url in your browser:

https://graph.facebook.com/v2.6/post_id/comments?fields=id,message,like_count,created_time,comments,from,attachment&order=chronological&access_token=ACCESS_TOCKEN_OF_YOUR_APP

this request return you the data requested in a json format containing :

  •     the id of the comment
  •     the message body of the comment
  •     the number of likes on this comment
  •     the date of the comment
  •     the user publishing the comment
  •     attachements

this comments are returned in a paging , it means you will get a limited part of the response. If you want more, you scroll down at the the end of the page, you will find 'paging', click-on , go to 'next', click-on the given url, and you will get the next page of response. ..

now, if you want to get more information about the fileds that you can request for comments, I invite you to read this reference : https://developers.facebook.com/docs/graph-api/reference/v2.11/comment

To get all the comments of a given page. I propose you this python (2.7) code. The logic is: 

This code will return you a csv file containing all the posts of the page.

2. After that, you will run this code of comments, which browses the file containing the posts , and for each post, it retrieves all its comments. the result will be stored in a CSV file.


don't forget to specify the name of the posts file (and it's url) in the code => I put you a comment their

Comments

Popular posts from this blog