Created
February 1, 2020 20:06
-
-
Save cuuupid/855083b921f1735da6c19254f8d0f82d to your computer and use it in GitHub Desktop.
fb-page-scrape.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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