This article was published as a part of the Data Science Blogathon.
“Looking for a needle in a haystack”. These lines portray the importance of quality data in the real world. What about the tons of data that are easily available but the quality data is like gold rare to find.
Gathering information across the web is web scraping, also known as Web Data Extraction & Web Harvesting. Nowadays data is like oxygen for startups & freelancers who want to start a business or a project in any domain. Suppose you want to find the price of a product on an eCommerce website. It’s easy to find but now let’s say you have to do this exercise for thousands of products across multiple eCommerce websites. Doing it manually; not a good option at all.
JavaScript is a popular programming language and it runs in any web browser.
Node JS is an interpreter and provides an environment for JavaScript with some specific useful libraries.
In short, Node JS adds several functionality & features to JavaScript in terms of libraries & make it more powerful.
Let’s get to understand web scraping using Node JS with an example. Suppose you want to analyze the price fluctuations of some products on an eCommerce website. Now, you have to list out all the possible factors of the cause & cross-check it with each product. Similarly, when you want to scrape data, then you have to list out parent HTML tags & check respective child HTML tag to extract the data by repeating this activity.
I’m using Visual Studio to run this task.
To create a package.json file, I need to run npm init and give a few details as needed in the below screenshot.
Need to run the below codes to install these libraries.
Once the libraries are properly installed then you will see these messages are getting displayed.
Call the required libraries:
I picked this website “https://www.bullion-rates.com/gold/INR/2007-1-history.htm” and want to scrape data of gold rates along with dates.
Node JS code looks like this to pass the URL & check the response code.
It’s quite easy to find the proper HTML tags in which your data is present.
To see the HTML tags; right-click and select the inspect option.
Select proper HTML Tags:-
If you noticed there are three columns in our table, so our HTML tag for table row would be “HeaderRow” & all the column names are present with tag “th” (Table Header).
And for each table row (“tr”) our data resides in “DataRow” HTML tag
Now, I need to get all HTML tags to reside under “HeaderRow” & need to find all the “th” HTML tags & finally iterate through “DataRow” HTML tag to get all the data within it.
After including the HTML tags, our code will be:-
Print the Data, so the code for this is like:-
If you go to a more granular level of HTML Tags & iterate them accordingly, you will get more precise data.
That’s all about web scraping & how to get rare quality data like gold.
I tried to explain Web Scraping using Node JS in a precise way. Hopefully, this will help you.
Find full code on
If you have any questions about the code or web scraping in general, reach out to me on
We will meet again with something new.
Till then,
Happy Coding..!