NodeJs simple web scraper using cheerio

NodeJs simple web scraper using cheerio package. Using web scraper we can get the special kind of information from another website. For example, If you want to get the quick news you can create the web scraper for getting the lists of news. Today, We learn NodeJs simple web scraper using cheerio

Let’s create the web scraper for fetching the recent 10 article titles from The Coding Stuff. Let’s start first we should install “cheerio” package.

npm install cheerio

After, Install “cheerio” package let’s create the web scraper code on Nodejs. Let’s create the file “index.js” then write the web scraper code.

var request = require('request');
var cheerio = require('cheerio');

request('https://thecodingstuff.com/', function(err, resp, html) {
        if (!err){
          const $ = cheerio.load(html);
          // console.log(html);
          $("h2.entry-title a").each(function(){
                console.log( $(this).html() );
          });
      }
});

Our web scraper is ready for getting the recent 10 post title form The coding stuff.

Let’s run the web scraper.

npm index.js

Output get something like

Custom validation rules in Laravel 5.5
jQuery select2 get selected value using jQuery.
Create your first Shortcode in WordPress
Laravel get user location using IP address
Laravel 5.5 get current login user detail
Laravel 5.5 HMVC modular structure
Laravel 5.5 create a first artisan console command
Create your first widget on WordPress
Your time is limited, so don’t waste  it living someone else’s life
Laravel export table data to excel sheet using Laravel excel

So, we get the recent 10 posts from the coding stuff.

 

 

Published by

Sherya

Hello there, I am developer currently working with the company at Pune and part-time freelancer. Always I welcome a new opportunity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s