0

I have a page with lots of posts in FB. I want to copy all post's text in a txt file. what should I do ? is there any shortcut way ? I scroll down untill all posts loaded and press ctrl + a and ctrl + c then paste in txt file, but some posts not copied completely, they copied till "See More".

how can I click all see mores in page ?

I tried this in Console :

$( document ).ready(function() {
  document.getElementsByclassName('see_more_link').click();
});

but it doesn't worked.

any Idea to solve problem ??

( Im sorry if my enlish writing is too weak :(( )

Hosein
  • 179
  • 1
  • 2
  • 10

2 Answers2

2

You may want to take a look at this Link: https://www.facebook.com/apps/site_scraping_tos_terms.php

Scraping is not allowed. If you want to get data from Facebook, you should use the API: https://developers.facebook.com/docs/.

For getting the feed of a Facebook Page with the API, take a look at this thread: Facebook PHP SDK 3.0 - How to get my page wall posts at any time?

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
0

I came here looking how to do it, can't find how. So I made it for myself.

This function is for running the loop in order (Thanks to Ivo Wetzel for his answer here):

function asyncLoop(iterations, func, callback) {
  var index = 0;
  var done = false;
  var loop = {
    next: function() {
      if (done) {
        return;
      }
      if (index < iterations) {
        index++;
        func(loop);
      } else {
        done = true;
        callback();
      }
    },
    iteration: function() {
      return index - 1;
    },
    break: function() {
      done = true;
      callback();
    }
  };
  loop.next();
  return loop;
}

This other is for emulate click in the links (can't remember where I see it):

function hacerClic(obj, callback) {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var canceled = !obj.dispatchEvent(evt);
  callback();
}

Last, we have two runs for asyncLoop, one for expand the answers:

var verRespuestas = document.getElementsByClassName("UFIReplySocialSentenceLinkText");
var i = 0;
asyncLoop(verRespuestas.length, function(loop) {
  hacerClic(verRespuestas[i], function(result) {
    loop.next();
    i++;
  })
}, function() {});

And other for expand the 'see more':

var verMas = document.getElementsByClassName("_5v47");
var j = 0;
asyncLoop(verMas.length, function(loop) {
  hacerClic(verMas[j], function(result) {
    loop.next();
    j++;
  })
}, function() {});

NOTE: If the 'see more' loop gives error is probably because DOM isn't fully loeaded yet.

Community
  • 1
  • 1
LogoS
  • 313
  • 1
  • 12