Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Facebook friends / people search backup in web browser
/* Facebook friends / people search backup in web browser
* Scroll down to your friends page or a people search page to load all profiles
* Copy-paste the script below in a web browser console (F12 key or Ctrl+Shift+K shortcut in a browser like Firefox) and execute the desired function
* A textarea will appear at the end of the page so you can copy the data and paste it in a text file before saving it as a CSV file
* You can then view your backup in a spreadsheet editor like LibreOffice Calc
* You can also compare the backup with another one to see who removed you from their friends list or who appeared in a new search (e.g. with the Linux diff command)
* If the friend changed their name or profile URL, you can still find them with their profile ID which is backed up in the last column (open facebook.com/PROFILE_ID in a web browser)
* The Facebook Graph API was not used because they are locking or deprecating most of their endpoints (e.g. https://developers.facebook.com/docs/graph-api/changelog/breaking-changes/#taggable-friends-4-4)
*/
var data = [];
function FacebookFriendsBackup()
{
var list = document.getElementsByClassName("uiProfileBlockContent");
var length = list.length;
// note: firstChild is a bit faster than firstElementChild: https://jsperf.com/firstelementchild-and-firstchild
for (var i = 0; i < length; ++i) {
var link = list[i].getElementsByTagName("a")[0];
data[i] = link.firstChild.nodeValue;
data[i] += "\t" + link.href;
var json = JSON.parse(link.getAttribute("data-gt"));
if (json) { // JSON data is null when the Facebook profile is deactivated
data[i] += "\t" + json.engagement.eng_tid; // get profile ID in case the Facebook user changes their profile URL
}
}
displayData();
}
// can be used to backup a people search (for example to see when someone from another country or city moves to a new city)
// some results could be missing since sometimes the city name is followed by the region instead of the country
function FacebookPeopleSearchBackup()
{
//var list = document.getElementById("browse_result_area").getElementsByClassName("FriendRequestOutgoing"); // missing results since friend button is disabled on some profiles
var list = document.querySelectorAll('#BrowseResultsContainer > div, [data-testid="results"] > div');
var length = list.length;
for (var i = 0; i < length; ++i) {
data[i] = JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;
// comment previous line and uncomment following lines if you want full name and profile URL also
/*var link = list[i].getElementsByTagName("a")[1];
data[i] = link.title;
data[i] += "\t" + link.href;
data[i] += "\t" + JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;*/
}
displayData();
}
// can be used to backup group members with things in common (https://www.facebook.com/groups/XXX/members_with_things_in_common/)
// some results could be missing since sometimes the city uses the original name instead of the translated name
function FacebookPeopleCommonBackup()
{
var list = document.querySelectorAll("[id^=things_in_common_]");
var length = list.length;
for (var i = 0; i < length; ++i) {
data[i] = list[i].id.substr(17);
// comment previous line and uncomment following lines if you want full name and profile URL also
/*var link = list[i].getElementsByTagName("a")[1];
data[i] = link.title;
data[i] += "\t" + link.href;
data[i] += "\t" + list[i].id.substr(17);*/
}
displayData();
}
function displayData()
{
var box = document.createElement("textarea");
box.value = data.join('\n');
document.body.appendChild(box);
}
@hoshi411

This comment has been minimized.

Copy link

@hoshi411 hoshi411 commented Mar 21, 2020

What is a web browser console?

@baptx

This comment has been minimized.

Copy link
Owner Author

@baptx baptx commented Mar 21, 2020

@hoshi411 it is a web browser area where you can execute custom JavaScript code, you can open it with the F12 key or Ctrl+Shift+K shortcut in a browser like Firefox (I just updated the script comment to mention this for people who are not familiar with it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.