I made this to help myself in future if in case i need to download again comment from Youtube video. Also i help you guys because there's no tutorial about this in documentation. I hope you like it.
Here, use this code and copy it in Google Colab, or Python IDE, or Kaggle Notebook, or Jupyter Notebook.
# Initiate Library
import pandas as pd
from youtube_comment_downloader import *
# Initiate Downloader and Youtube_url
downloader = YoutubeCommentDownloader()
Youtube_URL = #Input Youtube video URL that you want to extract it's comment
comments = downloader.get_comments_from_url(Youtube_URL, sort_by=SORT_BY_POPULAR)
# Initiate a dictionary to save all comments from Youtube Video
all_comments_dict = {
'cid': [],
'text': [],
'time': [],
'author': [],
'channel': [],
'votes': [],
'replies': [],
'photo': [],
'heart': [],
'reply': [],
'time_parsed': []
}
# Take all comment and save it in dictionary using for loop
for comment in comments:
for key in all_comments_dict.keys():
all_comments_dict[key].append(comment[key])
# Convert Dictionary to Dataframe using Pandas
comments_df = pd.DataFrame(all_comments_dict)
# Display Dataframe
display(comments_df)
I made this to help myself in future if in case i need to download again comment from Youtube video. Also i help you guys because there's no tutorial about this in documentation. I hope you like it.
Here, use this code and copy it in Google Colab, or Python IDE, or Kaggle Notebook, or Jupyter Notebook.
If you want to save it add this:
Save in excel file
Save in CSV file