npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flipkart-scraper

v2.0.0

Published

[![NPM](https://nodei.co/npm/flipkart-scraper.png)](https://nodei.co/npm/flipkart-scraper/)

Downloads

17

Readme

NPM

Flipkart Scraper

This package will help us to scrape all Flipkart products through Flipkart affiliate API.

Please refer API Documentation here.

See the Examples here

Installation

Install using 'npm'

npm i flipkart-scraper

Install using 'yarn'

yarn add flipkart-scraper

Usage

import { FlipkartScraper } from "flipkart-scraper";

const scraper = new FlipkartScraper(
  "<Affiliate-Id-Here>",
  "<Affiliate-Token-Here>"
);

// 'data' event handler
scraper.on("data", (data) => {
  console.log(data.products.length);
});

// Start the scraper
scraper.start();

Class: FlipkartScraper

This module will help us to scrape all the Flipkart products.

constructor(affiliateId, affiliateToken, [options])

This will create instance of the FlipkartScraper class with required authentication params.

  • options {object}
    • concurrency? {number} Number for parallel processing in the queue, Default set to 2
    • maxRequest? {number} Maximum request to Flipkart affliate server, Default set to 0 - means unlimited
    • maxPage? {number} Maximum number of pages to scrape per category, Default set to 0 - means unlimited

Example

const scraper = new FlipkartScraper(
  "<Affiliate-Id-Here>",
  "<Affiliate-Token-Here>",
  {
    /**
     * It will make 5 parallel request to Flipkart.
     * This is optional param, default is set to 2
     **/
    concurrency: 5,
    /**
     * It will make only 500 request to Flipkart. After that program ends.
     * This is optional param, default is set to 0 means unlimited
     **/
    maxRequest: 500,
    /**
     * Maximum 3 request per category
     **/
    maxPage: 3,
  }
);

scraper.start([categoriesToScrape])

This method will start scraping through Flipkart affiliate API.

  • categoriesToScrape? {string[]} Pass the list of categories that you want to scrape. Default set to [] which means all categories.

Example

scraper.start(["telivision", "mobiles"]); // It will scrape only specified categories

scraper.stats(showAsNumbers?=false)

This method will show the stats of scraper. By default stats will come as numerals like (3.1k, 1.45GB)

  • showAsNumbers? {boolean} Stats will return as number instead of numerals.

Sample Stats

/*
{
  "startTime": "2021-02-21T08:14:29.445Z",
  "endTime": undefined, // endTime will be available once scraping finished
  "status": "inprogress",
  "concurrency": 30,
  "waitingRequests": 0,
  "productsCount": "19.54k",
  "elapsed": "0:00:06 10ms",
  "durationPerMillionProducts": "0:05:08 558ms",
  "productsPerSec": "3.25k products/sec",
  "avgResponseTime": "147ms",
  "requestPerSec": "7/sec",
  "requestedCount": "43.00",
  "processedCount": "41.00",
  "errorCount": "0.0",
  "retryCount": "0.0",
  "retryHaltCount": "0.0",
  "pendingCategory": 2,
  "completedCategory": 1,
  "downloadSize": "84.78MB",
  "downloadedSpeed": "14.11MB/sec",
  "info": {
    "pendingCategories": [
      {
        "category": "mens_clothing",
        "startTime": "2021-02-21T08:14:29.602Z",
        "noOfPages": 18,
        "elapsed": 5668,
        "totalProducts": 9000
      },
      {
        "category": "mobiles",
        "startTime": "2021-02-21T08:14:29.603Z",
        "noOfPages": 13,
        "elapsed": 5771,
        "totalProducts": 6500
      }
    ],
    "completedCategories": [
      {
        "category": "laptops",
        "noOfPages": 10,
        "totalProducts": 4500,
        "elapsed": 3878
      }
    ]
  }
}
*/

events: 'response'

Emitted when successful HTTP response from the Flipkart Affiliate server.

Example

// 'response' event handler
scraper.on("response", (response) => {
  console.log(response);
});

events: 'data'

Emitted when products returned from Flipkart affiliate API.

Example

// 'data' event handler
scraper.on("data", (data) => {
  console.log(data.apiData.products);
});

events: 'categoryCompleted'

Emitted when all products scraped for the category.

Example

// 'categoryCompleted' event handler
scraper.on("categoryCompleted", (completedCategoryInfo) => {
  console.log(completedCategoryInfo);
});

events: 'finished'

Emitted when scraper finished.

Example

// 'finished' event handler
scraper.on("finished", (info) => {
  console.log(info);
});

events: 'error'

Emitted if any errors occured.

Example

// Triggered if any error occured
scraper.on("error", (error) => {
  console.error(error);
});

events: 'retry'

Emitted if any retry occured.

Example

// Triggered if any retry occured
scraper.on("retry", (retryInfo) => {
  console.log(retryInfo);
});

events: 'retryHalted'

Emitted if any retries failed for 10 times.

Example

// Triggerd when retry failed 10 times
scraper.on("retryHalted", (retryHaltInfo) => {
  console.error(retryHaltInfo);
});