Skip to content

Instantly share code, notes, and snippets.

@Xnuvers007
Last active June 22, 2025 17:53
Show Gist options
  • Save Xnuvers007/4e936210ec249a883065e567a03ae2d1 to your computer and use it in GitHub Desktop.
Save Xnuvers007/4e936210ec249a883065e567a03ae2d1 to your computer and use it in GitHub Desktop.
(async function scrapeAndDownloadFacebookProfiles() {
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const scrollPauseTime = 3000; // Delay between scrolls
const scrollLimit = 50; // Safety limit for scrolling
let previousHeight = 0;
let scrollCount = 0;
console.log("πŸ”ƒ Scrolling page...");
while (scrollCount < scrollLimit) {
window.scrollTo(0, document.body.scrollHeight);
await delay(scrollPauseTime);
const currentHeight = document.body.scrollHeight;
if (currentHeight === previousHeight) {
console.log("βœ… Done scrolling.");
break;
}
previousHeight = currentHeight;
scrollCount++;
}
console.log("πŸ” Scraping profile links...");
const profiles = new Set();
const anchors = document.querySelectorAll('a[href*="facebook.com/profile.php?id="], a[href*="facebook.com/"][role="link"]');
anchors.forEach(a => {
const name = a.innerText.trim();
const href = a.href;
if (name && href && href.includes("facebook.com")) {
profiles.add(JSON.stringify({ name, url: href }));
}
});
const result = Array.from(profiles).map(p => JSON.parse(p));
console.log(`🎯 Found ${result.length} profiles`);
// Convert to CSV
const csvContent = "data:text/csv;charset=utf-8," +
["Name,URL"]
.concat(result.map(p => `"${p.name.replace(/"/g, '""')}","${p.url}"`))
.join("\n");
// Trigger download
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "facebook_profiles.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
console.log("πŸ“₯ CSV downloaded as `facebook_profiles.csv`");
})();
(function () {
// Step 1: Collect all anchor tags
const videoLinks = Array.from(document.querySelectorAll('a'))
.map(a => a.href)
.filter(href =>
href.includes('/watch') &&
href.includes('youtube.com')
);
// Step 2: Remove duplicates
const uniqueLinks = [...new Set(videoLinks)];
// Step 3: Convert to CSV format
const csvContent = "data:text/csv;charset=utf-8," +
["Video URL"].concat(uniqueLinks).join("\n");
// Step 4: Trigger download
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "youtube_video_links.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Optional: Log to console too
console.log(`βœ… Downloaded ${uniqueLinks.length} video links as CSV.`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment