Created
January 15, 2025 16:24
-
-
Save kukicado/e92b31601117060f6895ecefc989bf0f 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
(() => { | |
const profileURL = "https://www.tiktok.com/@YOURPROFILE"; | |
const allURLs = new Set(); | |
let scrollCount = 0; | |
const maxScrolls = 10; | |
async function scrapeURLs() { | |
console.log(`Scraping URLs from ${profileURL}...`); | |
// Function to extract URLs from the current page | |
const extractLinks = () => { | |
const links = document.querySelectorAll('a'); | |
links.forEach(link => { | |
const href = link.href; | |
if (href) { | |
allURLs.add(href); | |
} | |
}); | |
console.log(`Found ${allURLs.size} unique URLs so far.`); | |
}; | |
// Function to scroll down the page | |
const scrollDown = () => { | |
window.scrollTo(0, document.body.scrollHeight); | |
return new Promise(resolve => setTimeout(resolve, 1500)); // Wait for content to load | |
}; | |
// Initial extraction | |
extractLinks(); | |
while (scrollCount < maxScrolls) { | |
const initialURLCount = allURLs.size; | |
console.log(`Scrolling down (${scrollCount + 1}/${maxScrolls})...`); | |
await scrollDown(); | |
extractLinks(); | |
// Check if new URLs were loaded. If not, we might be at the end. | |
if (allURLs.size === initialURLCount) { | |
console.log("No new URLs found, likely reached the end."); | |
break; | |
} | |
scrollCount++; | |
} | |
console.log("\nAll unique URLs found on the TikTok page:"); | |
const sortedURLs = Array.from(allURLs).sort(); | |
sortedURLs.forEach(url => console.log(url)); | |
console.log(`\nTotal unique URLs found: ${allURLs.size}`); | |
} | |
// Execute the scraping function | |
scrapeURLs(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment