Asked 30+ days ago
4 Apr 2017
Views 449

jessica posted

how to parse website with Node JS ?

How to scrap website with Node JS ,
Mitul Dabhi

Mitul Dabhi
answered Feb 18 '18 20:17

two module of Node will help you to parse any website .

try to install cheerio and request module at node JS

npm install request 
npm install cheerio

Initialize request and cheerio at node script

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

try to get request

request('', function (error, response, html) {
        if (!error && response.statusCode == 200) {
            var $ = cheerio.load(html);
   $('script').each(function (i, element) { 
      a = $(this);

request function will give you response and cheerio help you to read it as per need

  var $ = cheerio.load(html);

cheerio.load will load html
and you can use cheerio other accessor function which help you to get html as we do in jQuery.

some example of usage of cheerio


it will give you text of first children of element which have data element id

use find to find elements in given html


it will find li element in element which have data element id , and give the length of li elements

Edit Answer
Mitul Dabhi

Mitul Dabhi
answered Feb 18 '18 20:17

to parse the website in Node Js
you can use Osmosis module also

try to install osmosis

npm install osmosis

code to fetch by node js module Osmosis
web scrapping by Node Js code is belowed ::

var osmosis = require('osmosis');

it easy to crawl website in Node JS with osmosis
Edit Answer
Post Answer