Skip to content

Instantly share code, notes, and snippets.

@cuuupid
Created February 1, 2020 20:06
Show Gist options
  • Save cuuupid/855083b921f1735da6c19254f8d0f82d to your computer and use it in GitHub Desktop.
Save cuuupid/855083b921f1735da6c19254f8d0f82d to your computer and use it in GitHub Desktop.
fb-page-scrape.js
// click all the see more links to expand the post
new Array(...document.getElementsByClassName('see_more_link_inner')).forEach(el => el.click())
// scrape all the post content to an array called "posts"
const posts = new Array(...document.getElementsByClassName('userContent')).map(el => el.innerText)
// https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
function downloadObjectAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
// download our posts to json content
downloadObjectAsJson(posts, 'posts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment