Facebook Comments for Research

Another Subversive Comment

This is a post about (at least temporary) failure. I should be able to do all this via the Facebook API/SDK but I’m doing something wrong. While I’m learning a decent amount in the land of programming, fundamentally I still suck.

With that cathartic self-flagellation out of the way . . .

I’m working with someone who wants to grab all the comments from a large number of CDC posts about health issues for some research. She is currently doing it by hand. Here are two improvements to that awful reality.1

Expand All Comments

In FB land if there are many comments you only see the most recent. And if there are many, many comments you have to keep hitting “View Previous Comments” over and over. That’s super boring to do once. If you have to do it a lot it would really suck. Enter Alec’s bookmarklet. I tweaked it a tiny bit because I think FB changed the wording but it works like a charm.

You’d copy the text below. Add a bookmark and then click edit. Replace the URL with this text and name it whatever you want.

javascript:function find_more_and_click(){function i(e){if(e.length<=0){return}e[0].click();window.setTimeout(function(){i(e.splice(1))},800)}var e=document.getElementsByClassName("UFIPagerLink");var t=[];for(var n=0;n<e.length;n++){if(e[n]&&(e[n].text=="View more replies"||e[n].text=="View previous comments")){t.push(e[n])}}var r=t.length;i(t);if(r>0){window.setTimeout(function(){find_more_and_click()},800)}}find_more_and_click()

Grab All Comments

Now to grab all these enlightening comments . . .

Install the Scraper Chrome Extension. You can now right click a particular item and choose “scrape similar.” It’ll pull up a grid of stuff chosen via xpath that’s similar to what you clicked on. You can then export to Google Drive or copy to your clipboard. There’s a quick video of what it looks like in action below.


1 If you must punch yourself in the face at least do it for a shorter duration.

Comments on this post

  1. sam said on October 19, 2015 at 8:03 pm

    thanks tom what about see more and replies any solution ?

    • Tom Woodward said on October 19, 2015 at 8:20 pm

      I ended up doing this for real with PHP. I wrote a post on it here.

  2. david said on December 1, 2015 at 10:12 am

    hello tom can you make bookmarklet for twitter to show all replies ?


    • Tom Woodward said on December 2, 2015 at 8:38 pm

      Because of the way Twitter does popup windows for this it wouldn’t work well (it could be done but the windows just pop open then close as it moves through). There may be some way to override that but I couldn’t figure it out.

  3. david said on December 2, 2015 at 9:47 pm

    as there any website or any one you know can help in this problem ?

    • Tom Woodward said on December 2, 2015 at 9:51 pm

      Best I can tell, you’d need to do it directly with the API and even then it’d be far more trouble than I’d have expected.

  4. david said on December 14, 2015 at 12:09 pm

    tom is there any forum you know where java expert gather maybe some one of them can help

    i dont know where i can find some one how can ehlp

    • Tom Woodward said on December 14, 2015 at 12:20 pm

      You’d be looking for someone into javascript rather than java (very different things despite the name overlap) if you want to go the current route. There are places where you can place bounties on programming jobs . . . I recently talked to a VCU student who might be the kind of person interested in this. He does both Java and javascript. He’s on toptal. I think Freelancer will do stuff like that as well but it’s not really my area of expertise.

      You might also consider what it is you really want/need and then the best way to get it. The bookmarklet is fine for some trivial browsing stuff but anything serious around collecting/analyzing data you’d probably want to be much more substantial.

  5. david said on February 2, 2016 at 2:32 pm

    hello tom i find the script for twitter is it possible to you now to make a bookmarklet




  6. david said on February 2, 2016 at 2:35 pm