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>"
);
scraper.on("data", (data) => {
console.log(data.products.length);
});
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 unlimitedmaxPage?
{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>",
{
concurrency: 5,
maxRequest: 500,
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"]);
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
events: 'response'
Emitted when successful HTTP response from the Flipkart Affiliate server.
Example
scraper.on("response", (response) => {
console.log(response);
});
events: 'data'
Emitted when products returned from Flipkart affiliate API.
Example
scraper.on("data", (data) => {
console.log(data.apiData.products);
});
events: 'categoryCompleted'
Emitted when all products scraped for the category.
Example
scraper.on("categoryCompleted", (completedCategoryInfo) => {
console.log(completedCategoryInfo);
});
events: 'finished'
Emitted when scraper finished.
Example
scraper.on("finished", (info) => {
console.log(info);
});
events: 'error'
Emitted if any errors occured.
Example
scraper.on("error", (error) => {
console.error(error);
});
events: 'retry'
Emitted if any retry occured.
Example
scraper.on("retry", (retryInfo) => {
console.log(retryInfo);
});
events: 'retryHalted'
Emitted if any retries failed for 10 times.
Example
scraper.on("retryHalted", (retryHaltInfo) => {
console.error(retryHaltInfo);
});