How to scrape the web data using cheerio in Node.js ? Last Updated : 11 Jan, 2023 Comments Improve Suggest changes Like Article Like Report Node.js is an open-source and cross-platform environment that is built using the chrome javascript engine. Node.js is used to execute the javascript code from outside the browser. Cheerio: Its working is based on jQuery. It's totally working on the consistent DOM model. Cheerio is used for scraping web data sometimes and also used for automated tasks. Approach: In this article, we scraped the data of world meter a covid info website where we get the total confirmed cases total number of death, and total patients who are recovered till now. Below is the step by step implementation: Step 1: Enter the cmd and type the below command which will create the package.json file npm init Step 2: After creating the package, JSON file you need to install the cheerio, request and chalk from the below command: npm install request cheerio chalk Step 3: Now your Project directory looks like this: Project Structure Step 4:Now we create the index.js file and write the below code: index.js const { Cheerio } = require("cheerio"); const request = require("request"); const cheerio = require("cheerio"); const chalk = require("chalk"); request("https://www.worldometers.info/coronavirus/", cb); function cb(error, response, html) { if (error) { console.error("Error:", error); } else { handleItem(html); } } function handleItem(html) { let setTool = cheerio.load(html); let contentArr = setTool("#maincounter-wrap span"); let total = setTool(contentArr[0]).text(); let death = setTool(contentArr[1]).text(); let recovered = setTool(contentArr[2]).text(); console.log(chalk.gray("Total cases:" + total)); console.log(chalk.red("Total Death:" + death)); console.log(chalk.green("Total cases:" + recovered)); } Output: Open the command prompt and enter the below command node index.jsOutput Comment More infoAdvertise with us Next Article How to scrape the web data using cheerio in Node.js ? N nishantsinghgfg Follow Improve Article Tags : Misc Web Technologies Node.js NodeJS-Questions Practice Tags : Misc Similar Reads How to Scrape a Website Using Puppeteer in Node.js ? Puppeteer is a Node.js library that provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It allows automating, testing, and scraping of web pages over a headless/headful browser. Installing Puppeteer: To use Puppeteer, you must have Node.js installed. Then, Pu 2 min read How to Retrieve Data from MongoDB Using NodeJS? MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term âNoSQLâ means ânon-relationalâ. It means that MongoDB isnât based on the table-like relational database structure but provides an altogether different mechanism for the storage and retrieval of data. Thi 3 min read What is Web Scraping in Node.js ? Web scraping is the automated process of extracting data from websites. It involves using a script or a program to collect information from web pages, which can then be stored or used for various purposes such as data analysis, research, or application development. In Node.js, web scraping is common 3 min read How to add Search Feature in Next.js using Algolia ? Adding a search feature to your Next.js application can greatly enhance user experience by providing fast and relevant search results. Algolia is a powerful search-as-a-service solution that integrates seamlessly with Next.js to offer instant, full-text search capabilities. In this article, we will 3 min read How to Use ChatGPT API in NodeJS? ChatGPT is a very powerful chatbot by OpenAI that uses Natural Language Processing to interact like humans. It has become very popular among developers and is being widely used for some of its state-of-the-art features, like understanding and interpreting code, and even generating code based on text 4 min read Like