Last active
June 22, 2025 17:53
-
-
Save Xnuvers007/4e936210ec249a883065e567a03ae2d1 to your computer and use it in GitHub Desktop.
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 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`"); | |
})(); |
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
(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