Created
October 19, 2019 08:20
-
-
Save NicoWeio/646f59e15e1c55cfbdfed47836555559 to your computer and use it in GitHub Desktop.
WhatsApp Web Profile Picture Scraper - just paste into the console!
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
async function scrape() { | |
let allChats = []; | |
for (let i = 0; i < 250; i++) { | |
let allChatElements = document.querySelectorAll(".X7YrQ"); | |
console.log("Iter ", i, allChatElements.length, " elements"); | |
for (let k = 0; k < allChatElements.length; k++) { | |
try { | |
let c = allChatElements[k]; | |
let title = c.querySelector("._19RFN").innerText; | |
let image = (c.querySelector("img") || {}).src; | |
if (!allChats[title] && image && image.startsWith('http')) { | |
allChats[title] = image; | |
console.log(title, image); | |
} | |
} catch (e) { | |
console.warn(e); | |
} | |
} | |
document.querySelector("#pane-side").scrollTop += 72; | |
await sleep(200); | |
} | |
let allChatsConv = []; | |
for (const [key, value] of Object.entries(allChats)) { | |
console.log(key, value); | |
allChatsConv.push({ | |
title: key, | |
image: value | |
}); | |
} | |
console.log(allChatsConv); | |
return allChatsConv; | |
} | |
async function showDownloadLinks(list) { | |
let newEl = document.createElement('div'); | |
newEl.innerHTML = `<div class="pp-dl" style="position: absolute; left: 50%; top: 50%; background: #4cec66; height: 100px; width: 250px; z-index: 100000000000; box-shadow: 10px 10px 5px;"> | |
<a id="dl">DOWNLOAD</a> | |
</div>`; | |
document.body.insertBefore(newEl, document.body.firstChild); | |
document.getElementById('dl').addEventListener("click", nextDownloadLink); | |
} | |
var downloadLinkIndex = 0; | |
async function nextDownloadLink() { | |
let item = l[downloadLinkIndex]; | |
let a = document.getElementById("dl"); | |
let extraReq = await fetch(item.image); //necessary to get the full resolution | |
await sleep(500); | |
let file = await fetch(item.image).then(r => r.blob()); | |
a.href = URL.createObjectURL(file); | |
a.innerHTML = "DOWNLOAD " + item.title + "(" + downloadLinkIndex + "/" + l.length + ")"; | |
a.download = item.title + " " + timestamp(); | |
downloadLinkIndex++; | |
} | |
function timestamp() { | |
let d = new Date().toISOString().replace(/[-TZ\.:]/g, ''); | |
return d.slice(0, 8) + "_" + d.slice(8, 14); | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
var l = await scrape(); | |
await showDownloadLinks(l); | |
alert("That might help you: \nxdotool click --delay 2000 --repeat 250 1"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment