logo
languageENdown
menu

Scrape YouTube Comments for Sentiment Analysis

5 min read

Are you looking for a YouTube comment scraper for sentiment analysis? If yes, then you have come to the right place. This article helps you to scrape YouTube comments using the two easiest methods.

Currently, YouTube has over 2+ billion active users per month. The videos on YouTube are full of thousands of users’ comments. Scraping these YouTube comments can help you do many cool and exciting things. The information mined from YouTube comments can help you build machine learning models, perform user sentiment analysis, create large datasets, and perform data analysis.

So, whether you are a researcher, a student, or a data engineer, the following content can help you get YouTube comments for further analysis. Let’s see different methods to extract YouTube comments data with and without coding.

If you are wondering whether YouTube comment scraping is legal or not, the short answer is YES, it is legal.

YouTube contains thousands of data valid for research, marketing, and ads. Most of the public comments on a YouTube video give a good insight into what users think about the posted video.

Since the YouTube comments data is publicly available, you can easily copy-paste it into a spreadsheet or excel and create a dataset. Using that dataset, you can perform sentiment analysis or apply your AI algorithms to it.

But, manually copying data to an Excel sheet is time-consuming and not an appropriate solution if a video has thousands of comments. That is why you need web scraping tool.

Web scraping is a way to read data of a website using an automated tool or programming script. Once the data is read, the tool helps you save and store the publicly available big data in an organized format that you can use for research, i.e., sentiment analysis.

Therefore, it is legal to scrape YouTube comments because they are meant for the public. Not only YouTube comments, but you can scrape any publicly available data on the internet, and it is legal to do so.

Free YouTube Comments Scraper No-Coding Asked

The previous section was essential to help you understand that YouTube comments scraping is legal. Here we’ll talk about how to get the comments easily with the best YouTube comment scraper – Octoparse. It is a highly reliable tool that does not require any computer programming skills. You can easily download all YouTube comments into your desired format like Excel. The tool provides a great UI that is easy for any beginner to use.

Key Features of Octoparse 

  • User-friendly because it requires no code and three steps of data scraping.
  • It supports all types of Websites.
  • It allows you to export scraped data into many different formats.
  • Octoparse cloud service automates your repetitive data scraping.
  • IP rotation features help you from being blocked while data scraping.

Steps to scrape YouTube comments with Octoparse

Step 1: Paste the YouTube URL to Octoparse

Before beginning, you need to download and install Octoparse on your device, and sign up for a free account. Copy and paste your desired YouTube video URL in the search bar, and click on the Start button. Octoparse will load the page by auto-detecting.

You can also search YouTube comments on the search bar and find the preset template. You can preview the data sample and use it to scrape with only a few clicks.

scrape youtube comments with Octoparse

 

Step 2: Customize YouTube comment scraping workflow

Octoparse will automatically create a YouTube comments crawler for you. You can make changes with the Tips it given to check all data you want can be found in the preview table. You can quickly delete any fields that you do not wish to scrape or rename.

Step 3: Scrape YouTube comments and download

Click the Save button in the upper-right corner to save the task you created in Octoparse. After that, hit the Run button and wait until Octoparse finishes its job. You can download the scraped YouTube comments in your desired format.

You can also scrape other information from YouTube channel, reading this article: How to Build A YouTube Channel Crawler, or watching the video guide below to learn more details.

Video guide to scrape YouTube video info with Octoparse

Scrape YouTube Comments with Python

Python scripts provide another powerful way to scrape YouTube comments. But, this method is complex if you do not have computer programming experience.

Note: Make sure you have a Python environment setup on your computer before proceeding with this method.

How to scrape YouTube comments using Python programming language

Step 1: Install Google Chrome on your computer.

Step 2: Once done, install the ChromeDriver by clicking here.

Step 3: In your Python code, import the following libraries needed to perform YouTube comments data scraping.

import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

These libraries are needed to crawl through YouTube comments that are dynamically loaded. Don’t worry if you don’t know precisely the purpose of every library used in the process.

Step 4: Add the below code to scrape YouTube video comments.

data= []
youtube_video_url= "https://www.youtube.com/watch?v=kuhhT_cBtFU&t=2s"

with Chrome(executable_path=r'C:\Program Files\chromedriver.exe') as driver:
    wait = WebDriverWait(driver,15)
    driver.get(youtube_video_url)
 
   for item in range(200):
        wait.until(EC.visibility_of_element_located((By.TAG_NAME, "body"))).send_keys(Keys.END)
        time.sleep(15)


    for comment in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#content"))):
        data.append(comment.text)

Here, you have created a Python loop that will loop through the comments of your YouTube video and, during each iteration, append the scraped comments in the data field. Also, change the YouTube video link to your desired video from the youtube_video_url variable.

Step 5: Visualize the scraped YouTube comments using Python’s Pandas library. You need to add the following lines of code at the end of your python file.

import pandas as pd
df = pd.DataFrame(data, columns=['comment']
df.head()

Final Thoughts

Now, you have learned how to scrape YouTube comments both coding and no-coding. The first is to use Octoparse no-code free tool, and the second is by using a Python script. However, you need to have some programming skills to scrape YouTube comments with Python. Choose the one which can meet your needs better.

Hot posts

Explore topics

image
Get web automation tips right into your inbox
Subscribe to get Octoparse monthly newsletters about web scraping solutions, product updates, etc.

Get started with Octoparse today

Download

Related Articles