Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading 0 people #6

Open
nf24eg opened this issue Jun 19, 2023 · 8 comments
Open

loading 0 people #6

nf24eg opened this issue Jun 19, 2023 · 8 comments

Comments

@nf24eg
Copy link

nf24eg commented Jun 19, 2023

hello, I have a group with 16k usersm and the code loading zero of them :(
Untitled

@MartianDominic
Copy link

same here

@floriandiud
Copy link
Owner

Hello,

Thanks for the screenshot. Have you pasted the script before scrolling on the members tab? Can you share a screenshot with the "Console" tab visible from the Developer Tools?

@MartianDominic
Copy link

MartianDominic commented Jun 20, 2023 via email

@floriandiud
Copy link
Owner

Thx @MartianDominic Can you share the changes you made?

@steverob1066
Copy link

Did anyone find out what is going wrong with the script? I have the same problem. It works with some groups and not others.

@MartianDominic
Copy link

MartianDominic commented Oct 31, 2023

I haven't used it in a while, but these are the changes I made to fetch members with things in common back then. Here's the full script:
`
function exportToCsv(filename, rows) {
var processRow = function(row) {
var finalVal = '';
for (var j = 0; j < row.length; j++) {
var innerValue = (row[j] === null || typeof row[j] === "undefined") ? '' : row[j].toString();
if (row[j] instanceof Date) {
innerValue = row[j].toLocaleString();
}
var result = innerValue.replace(/"/g, '""');
if (result.search(/("|,|\n)/g) >= 0) {
result = '"' + result + '"';
}
if (j > 0) {
finalVal += ',';
}
finalVal += result;
}
return finalVal + '\n';
};

var csvFile = '';
for (var i = 0; i < rows.length; i++) {
  csvFile += processRow(rows[i]);
}

var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' });

var link = document.createElement("a");
if (link.download !== undefined) {
  var url = URL.createObjectURL(blob);
  link.setAttribute("href", url);
  link.setAttribute("download", filename);
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

}

var members_list = [
['Profile Id', 'Full Name', 'ProfileLink', 'Bio', 'Image Src', 'Group Id', 'Group Joining Text', 'Profile Type', 'isVerified', 'friendshipStatus', 'mutualFriends']
];

function buildCTABtn() {
var canvas = document.createElement('div');
var canvasStyles = [
'position: fixed;',
'top: 0;',
'left: 0;',
'z-index: 10;',
'width: 100%;',
'height: 100%;',
'pointer-events: none;'
];
canvas.setAttribute('style', canvasStyles.join(''));

var btn = document.createElement('div');
var btnStyles = [
  'position: absolute;',
  'bottom: 30px;',
  'right: 130px;',
  'color: white;',
  'min-width: 150px;',
  'background: var(--primary-button-background);',
  'border-radius: var(--button-corner-radius);',
  'padding: 0px 12px;',
  'cursor: pointer;',
  'font-weight: 600;',
  'font-size: 15px;',
  'display: inline-flex;',
  'pointer-events: auto;',
  'height: 36px;',
  'align-items: center;',
  'justify-content: center;'
];
btn.setAttribute('style', btnStyles.join(''));

var downloadText = document.createTextNode('Download\u00A0');
var numberSpan = document.createElement("span");
numberSpan.setAttribute('id', 'fb-group-scraper-number-tracker');
numberSpan.textContent = "0";
var memberText = document.createTextNode('\u00A0members');

btn.appendChild(downloadText);
btn.appendChild(numberSpan);
btn.appendChild(memberText);

btn.addEventListener('click', function() {
  var timestamp = new Date().toISOString();
  exportToCsv('groupMemberExport-' + timestamp + '.csv', members_list);
});

canvas.appendChild(btn);
document.body.appendChild(canvas);

return canvas;

}

function processResponse(dataGraphQL) {
console.log("Processing API response:", dataGraphQL);
if (!dataGraphQL.data) {
return;
}

var data = dataGraphQL.data;
var membersEdges;

if (data.node && data.node.group_member_discovery && data.node.group_member_discovery.edges) {
  membersEdges = data.node.group_member_discovery.edges;
} else {
  return;
}

var membersData = membersEdges.map(function(memberNode) {
  var id = memberNode.node.id;
  var name = memberNode.node.name;
  var bio_text = memberNode.node.bio_text?.text || '';
  var url = memberNode.node.url;
  var profile_picture = memberNode.node.profile_picture?.uri || '';
  var profileType = memberNode.node.__isProfile;

  var joiningText = memberNode.join_status_text?.text || memberNode.membership?.join_status_text?.text;
  var groupId = memberNode.node.group_membership?.associated_group?.id;

    
  var isVerified = memberNode.node.is_verified || false;
//   var messageSendingUri = memberNode.node.primaryActions.find(action => action.profile_action_type === 'MESSAGE').uri || '';
//   var contextualMessageRequestState = memberNode.node.secondaryActions[0]?.contextual_message_request_state || '';
//   var shouldRedirectMessageToPageInbox = memberNode.node.should_redirect_message_to_page_inbox || false;
try {
  var mutualFriends = memberNode.node.timeline_context_items.edges[0].node.title.text || '';
} catch (error) {
  var mutualFriends = ''
}
try{
  var friendshipStatus = memberNode.node.user_type_renderer.user.friendship_status || '';
} catch (error) {
  var friendshipStatus = ''
}
  return [
    id,
    name,
    url,
    bio_text,
    profile_picture,
    groupId,
    joiningText || '',
    profileType,
    isVerified,
    friendshipStatus,
    // messageSendingUri,
    // contextualMessageRequestState,
    // shouldRedirectMessageToPageInbox,
    mutualFriends
  ];
});

members_list.push(...membersData);

var tracker = document.getElementById('fb-group-scraper-number-tracker');
if (tracker) {
  tracker.textContent = members_list.length.toString();
}

}

function parseResponse(dataRaw) {
console.log("Parsing API response:", dataRaw);
var dataGraphQL;

try {
  dataGraphQL = JSON.parse(dataRaw);
} catch (err) {
  console.error('Failed to parse API response', err);
  return;
}

processResponse(dataGraphQL);

}

function main() {
buildCTABtn();

var matchingUrl = '/api/graphql/';
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
  this.addEventListener('readystatechange', function() {
    if (this.responseURL.includes(matchingUrl) && this.readyState === 4) {
      console.log("API response received:", this.responseText);
      parseResponse(this.responseText);

      // Generate a random delay between 4 and 8 seconds
      var delay = Math.random() * (8000 - 4000) + 4000;

      // Scroll to the bottom of the page with a slow scroll
      scrollToBottomSlowly(delay);
    }
  }, false);
  send.apply(this, arguments);
}

}

function scrollToBottomSlowly(delay) {
var currentPosition = window.pageYOffset;
var targetPosition = document.body.scrollHeight;
var distance = targetPosition - currentPosition;
var scrollStep = Math.PI / (delay / 15);
var count = 0;
var scrollInterval = setInterval(function() {
var newPosition = currentPosition + distance * Math.sin(scrollStep * count);
window.scrollTo(0, newPosition);
count++;
if (count >= delay / 15) {
clearInterval(scrollInterval);
}
}, 15);
}

main();

`

@steverob1066
Copy link

Thanks - I'm afraid it still doesn't grab group members for me - I guess Meta changed things...

@ttulttul
Copy link

The code pasted above works for me if I go to the group, navigate to the Members tab, paste the code, hit enter, and then go back into the members are and scroll my mouse down. Once scrolling is triggered, the code starts working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants