0% found this document useful (0 votes)
406 views4 pages

Extract WhatsApp Group Contacts to CSV

This document contains JavaScript code to extract contact information from a WhatsApp group and export it to a CSV file. It selects the participant elements, loops through to get name, number, image and other details for each contact. It builds a CSV string with headers and rows of data, and generates a download link to trigger the file download.

Uploaded by

mailbabu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
406 views4 pages

Extract WhatsApp Group Contacts to CSV

This document contains JavaScript code to extract contact information from a WhatsApp group and export it to a CSV file. It selects the participant elements, loops through to get name, number, image and other details for each contact. It builds a CSV string with headers and rows of data, and generates a download link to trigger the file download.

Uploaded by

mailbabu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// var obj = document.

getElementsByClassName("infinite-list-viewport")
[0].getElementsByClassName("infinite-list-item infinite-list-item-transition");
// var topOfList = [Link]("_2wP_Y");
// [Link] = 50;

// old = $("[Link]-body").scrollTop()
// $("[Link]-body").scrollTop(old + 72)

//Click the group Icon to open the Group info Window to the side
// var openWAGroup = [Link]("_18tv-");
var openWAGroup = [Link]("_3V5x5")
[0].getElementsByClassName("_1lpto")
openWAGroup[0].click();

//Click the more Contacts button


var btnClick_more = [Link]("_3p0T6");
btnClick_more[0].click();

// $("html, body").scrollTop(0);
// SELECT "GROUP INFO" ELEMENT AS A WHOLE
var scrollUp = [Link]("_2sNbV")[0];
// [Link] = 0;

// setTimeout(() => {
// [Link] = [Link];

// }, 3000);

// var obj = [Link]("RLfQR")


[0].getElementsByClassName("_2wP_Y");

//SELECT ALL PARTICIPANTS ELEMENT


//var obj = [Link]("_37f_5")
[0].getElementsByClassName("_3HZor")[0].getElementsByClassName("_3xdMj");
var obj = [Link]("_3xdMj")
[0].getElementsByClassName("_3La1s")[0].getElementsByClassName("X7YrQ");
var data = [];

setTimeout(function() {
for (var i = 0; i < [Link]; i++) {

//GET PHONE NUMBER OR NAME IF ALREADY IN CONTACT


// var num = obj[i].getElementsByClassName("emojitext ellipsify")[0].title;
var namenum = obj[i].getElementsByClassName("_3H4MS")[0].innerText;

// var img = obj[i].getElementsByClassName("avatar-image is-loaded")


[0].[Link]("t=s", "t=l");

//GET PROFILE IMAGE AND REPLACE WITH LARGE SIZE INSTEAD OF THUMBNAIL
// try {var img = obj[i].getElementsByClassName("_3RWII")
[0].[Link]("t=s", "t=l");
try {var img = obj[i].getElementsByClassName("_3RWII")
[0].getElementsByClassName("jZhyM _13Xdg")[0].src;
var num = [Link](/u=(\d*)/)[1];}
catch (err) { var img = "No Pic";
num = [Link](/\d+/g); }
// img = [Link]("t=s", "t=l");

//GET SCREEN NAME


// try { var name = obj[i].getElementsByClassName("emojitext screen-
name-text")[0].outerText; }
try { var name = obj[i].getElementsByClassName("_3VvbK")
[0].outerText; }
catch (err) {
var name = namenum;
namenum = "IN_CONTACTS";
}

//GET STATUS TEXT


// try { var status = obj[i].getElementsByClassName("emojitext")
[1].title }
try { var status = obj[i].getElementsByClassName("_2Bw3Q")
[0].getElementsByClassName("_19RFN")[0].title }
catch (err) { var status = "NONE" }

data[i] = { num: num, namenum: namenum, name: name, img: img, status:
status };
}

/* $(document).ready(function(){
$('button').click(function(){
var data = $('#txt').val();
if(data == '')
return;

JSONToCSVConvertor(data, "Whatsapp Contacts", true);


});
});
*/
// function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel) {
//If JSONData is not an object then [Link] will parse the JSON string in
an Object
// var arrData = typeof JSONData != 'object' ? [Link](JSONData) :
JSONData;
var arrData = typeof data != 'object' ? [Link](data) : data;

var CSV = '';


//Set Report title in first row or line

// CSV += ReportTitle + '\r\n\n';


var ReportTitle = "Whatsapp Contacts";
CSV += ReportTitle + '\r\n\n';
CSV += "Group Name : " + [Link]("_19vo_")
[0].getElementsByClassName("_19RFN")[0].title + '\r\n' + "Number of participants :
" + [Link] + '\r\n\n';
//CSV += "Group Name : " +
[Link]('//*[@id="main"]/header/div[2]/div[1]/div/span', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).[Link] + '\r\n' +
"Number of participants : " + [Link] + '\r\n\n';

//This condition will generate the Label/Header


// if (ShowLabel) {
if (true) {
var row = "";
//This loop will extract the label from 1st index of on array
for (var index in arrData[0]) {

//Now convert each value to string and comma-seprated


row += index + ',';
}

row = [Link](0, -1);

//append Label row with line break


CSV += row + '\r\n';
}
//1st loop is to extract each row
for (var i = 0; i < [Link]; i++) {
var row = "";

//2nd loop will extract each column and convert it in string comma-
seprated
for (var index in arrData[i]) {
row += '"' + arrData[i][index] + '",';
}
[Link](0, [Link] - 1);

//add a line break after each row


CSV += row + '\r\n';

}
/* if (CSV == '') {
alert("Invalid data");
return;
} */

//Generate a file name


var fileName = "WAGroup_";
//this will remove the blank-spaces from the title and replace it with an
underscore
// fileName += [Link]("input-wrapper locked")
[0].getElementsByTagName("div")[1].[Link](/ /g,"_");
fileName +=
[Link]('//*[@id="main"]/header/div[2]/div[1]/div/span', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).[Link](/
/g,"_");

//Initialize file format you want csv or xls


var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);

// Now the little tricky part.


// you can use either>> [Link](uri);
// but this will not work in some browsers
// or you will not get the correct file extension

//this trick will generate a temp <a /> tag


var link = [Link]("a");
[Link] = uri;

//set the visibility hidden so it will not effect on your web-layout


[Link] = "visibility:hidden";
[Link] = fileName + ".csv";
//this part will append the anchor tag and remove it after automatic click
[Link](link);
[Link]();
[Link](link);
// }
}, 2000);

You might also like