Skip to content

Instantly share code, notes, and snippets.

@ashtonmeuser
Last active April 20, 2025 15:36
Show Gist options
  • Save ashtonmeuser/7d9a38a2a5ed9ff07a977ad770eeee3b to your computer and use it in GitHub Desktop.
Save ashtonmeuser/7d9a38a2a5ed9ff07a977ad770eeee3b to your computer and use it in GitHub Desktop.
Scrape TikTok captions
(() => {
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