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 ? 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 How to get Trending GitHub Repositories Using Node.js ? Approach: Fetch the entire HTML page and store it as string using request package.Load HTML into cheerio and find the CSS selectors to extract repositories details. Using request package: request package: The request is designed to be the simplest way possible to make http calls. It supports HTTPS a 2 min read How to Make GET call to an API using Axios in JavaScript? Axios is a promise-based HTTP client designed for Node.js and browsers. With Axios, we can easily send asynchronous HTTP requests to REST APIs and perform create, read, update and delete operations. It is an open-source collaboration project hosted on GitHub. It can be imported in plain JavaScript o 3 min read What are Request and Cheerio in Node.js NPM ? In this article, we are going to learn about that request and the cheerio library of node.js with their installation. Request Library: The request module is a very popular library in node.js. It helps in sending the request to the external web application to make the conversation between the client 3 min read Python | Tools in the world of Web Scraping Web page scraping can be done using multiple tools or using different frameworks in Python. There are variety of options available for scraping data from a web page, each suiting different needs. First, let's understand the difference between web-scraping and web-crawling. Web crawling is used to in 4 min read How to write âBeautiful Lifeâ in Node.js ? Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and itâs not a programming language. Most people are confused and understand itâs a framework or a programming language. We often use 1 min read Like