Last active
June 2, 2022 19:18
-
-
Save YSaxon/ea20986a5f4eaf5c04b6dfbb24ccc57b to your computer and use it in GitHub Desktop.
Browser console script to scrape all contacts from https://contacts.google.com/directory
This file contains hidden or 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
//Just paste this into your console while scrolled to the top of https://contacts.google.com/directory | |
//Adapted from https://github.com/KihtrakRaknas/DirectoryScraper/ | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
totalnum = parseInt(document.querySelector("#yDmH0d > c-wiz:nth-child(15) > div > div:nth-child(3) > div:nth-child(1) > div").innerHTML.replace(/\D+/g, "")); | |
let contacts = []; | |
//let names = []; | |
let ids = new Set(); //to make sure it doesn't duplicate entries | |
while (contacts.length < totalnum) { | |
for (contact of document.getElementsByClassName("zYQnTe")) { | |
let id = contact.dataset.id | |
let link = "https://contacts.google.com/person/" + id | |
let name = contact.getElementsByClassName("PDfZbf")[0].innerHTML | |
let job = contact.getElementsByClassName("E6Tb7b ZAFZMe")[0].innerHTML | |
let phone = contact.getElementsByClassName("E6Tb7b b62A4e")[0].innerText | |
let email = contact.getElementsByClassName("hUL4le")[0].innerHTML | |
let image = contact.getElementsByClassName("HfynVe")[0].src | |
if (!ids.has(id)) { | |
contacts.push({ id, link, name, job, email, phone, image }); | |
ids.add(id); | |
//names.push(name) | |
} | |
} | |
document.getElementsByClassName("E6Tb7b psZcEd")[document.getElementsByClassName("E6Tb7b psZcEd").length - 1].scrollIntoView(); | |
await sleep(150); | |
} | |
JSON.stringify(contacts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment