Are you interested in extracting video titles and URLs from a TikTok channel for further analysis or reference?
In this tutorial, we will walk you through a step-by-step process using JavaScript code to export video titles and URLs from any TikTok channel.
By following this guide, you’ll be able to automate the data extraction process and organize the information as per your requirements. So, let’s get started!
Learn How to Copy TikTok channel video URLs using code in 2023
- Step 1: Open the TikTok Channel Page To begin, open your preferred web browser and navigate to the TikTok channel page from which you want to export the video titles and URLs.
For demonstration purposes, let’s use the channel page for Google, which can be accessed by visiting “https://www.tiktok.com/@google“. - Step 2: Open the Browser Console To proceed with the data extraction process, we need to open the browser console.
This can be done by simply pressing the F12 key on your keyboard.
Once the console is open, you’ll be able to paste the provided JavaScript code snippets. - Step 3: Initiate Automated Scrolling In the console, paste the first code snippet labeled as “Code snippet 1”.
This code snippet will initiate an automated scrolling action, allowing us to gather all the necessary data from the TikTok channel. Here’s the code snippet:
//COPY & PASTE CODE 1:
let goToBottom = setInterval(() => window.scrollBy(0, 400), 1000);
After pasting the code (and pressing ENTER key), the page will start scrolling automatically. You need to wait until the scrolling reaches the bottom of the page. This scrolling action ensures that we collect all the video titles and URLs from the TikTok channel.
Step 4: Extract Video Titles and URLs Once the scrolling stops, you can proceed to paste the second code snippet labeled as “Code snippet 2”. This code snippet will extract the video titles and URLs and display them in the console. Here’s the code snippet:
//COPY & PASTE CODE 2:
clearInterval(goToBottom);
let arrayVideos = [];
console.log('\n'.repeat(50));
const containers = document.querySelectorAll('[class*="-DivItemContainerV2"]');
for (const container of containers) {
const link = container.querySelector('[data-e2e="user-post-item"] a');
const title = container.querySelector('[data-e2e="user-post-item-desc"] a');
//If the link is https://www.tiktok.com/, set it as the current page URL
if (link.href === 'https://www.tiktok.com/') link.href = window.location.href;
arrayVideos.push(title.title + ';' + link.href);
console.log(title.title + '\t' + link.href);
}
After pasting the second code snippet, the console will display the video titles and URLs in the desired format. You can now choose to copy this data and paste it into a spreadsheet for further analysis or any other use.
Step 5: Optional Step – Export Data as a CSV File If you prefer to export the data as a CSV file, we have an optional step for you.
By following this step, you can download the data in CSV format with semicolon (;) as the separator.
To proceed with the optional step, copy the provided code snippet labeled as “Code snippet 3”. Here’s the code snippet:
//COPY & PASTE CODE 3:
let data = arrayVideos.join('\n');
let blob = new Blob([data], {type: 'text/csv'});
let elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = 'my_data.csv';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
By pasting the code snippet, a CSV file named “my_data.csv” will be automatically downloaded.
This file will contain the video titles and URLs in a format suitable for spreadsheet applications.
Code mirror: https://codepen.io/netgrowstech/pen/LYXRxLW