Node.js Puppeteer Project Scraping Youtube Comments of a Youtube Video Full Tutorial For Beginners

You are currently viewing Node.js Puppeteer Project Scraping Youtube Comments of a Youtube Video Full Tutorial For Beginners

Welcome folks today in this tutorial we will be building a simple node.js project in which we will be scraping all the comments of a youtube video and storing it in a text file using puppeteer scraping tool. All the source code is given below and a step by step youtube video is also shown below.

 

 

 

 

 

Install this only one dependency which we will need for this project. After it make the app.js file which will be the starting point of the application. Now in this we will be writing a simple puppeteer script to open a link of youtube video.

 

 

Now we will force the puppeteer library to go to a certain url

 

Now we will bind a certain error event on puppeteer. When any error occurs in puppeteer then this will be fired then automatically the browser will close and we will render all the comments of the video into the comments array

 

 

For this you need to globally declare the comments array right here at the top of the application

 

Now we will wait for the necessary items to be loaded on the page

 

In this block of code we are waiting for the correct no of comments to be displayed on the screen and also for the comments to load properly

Now we will loop through all the comments of the video and push that comments to the comments array. And also last we will save that array to the comments.txt file using the fs module which is a built in module for node.js

 

 

Full Source Code

 

 

 

DOWNLOAD SOURCE CODE

 

Leave a Reply