Last active
April 20, 2025 15:36
-
-
Save ashtonmeuser/7d9a38a2a5ed9ff07a977ad770eeee3b to your computer and use it in GitHub Desktop.
Scrape TikTok captions
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 matchingDivs = Array.from(document.querySelectorAll('div')).filter(div => | |
Array.from(div.classList).some(cls => | |
['DivDescriptionContentContainer', 'DivDesContainer', 'DivVideoDescription'].some(sub => cls.includes(sub)) | |
) | |
); | |
const lines = matchingDivs.map(div => | |
`"${div.innerText.trim().replace(/"/g, '""')}"` | |
); | |
const proceed = confirm(`Found ${lines.length} captions. Do you want to download them as CSV?`); | |
if (!proceed) return; | |
const content = `text,label\n${lines.join('\n')}`; | |
const blob = new Blob([content], { type: 'text/csv;charset=utf-8;' }); | |
const link = document.createElement('a'); | |
link.href = URL.createObjectURL(blob); | |
link.download = 'data.csv'; | |
document.body.appendChild(link); // Required for Firefox | |
link.click(); | |
document.body.removeChild(link); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment