This package will help us to scrape all Flipkart products through Flipkart affiliate API.
Please refer API Documentation here.
See the Examples here
Install using 'npm'
npm i flipkart-scraper
Install using 'yarn'
yarn add flipkart-scraper
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();
- extends EventEmitter
This module will help us to scrape all the Flipkart products.
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 to2
maxRequest?
{number} Maximum request to Flipkart affliate server, Default set to0
- means unlimitedmaxPage?
{number} Maximum number of pages to scrape per category, Default set to0
- 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,
}
);
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
Emitted when successful HTTP response from the Flipkart Affiliate server.
Example
// 'response' event handler
scraper.on("response", (response) => {
console.log(response);
});
Emitted when products returned from Flipkart affiliate API.
Example
// 'data' event handler
scraper.on("data", (data) => {
console.log(data.apiData.products);
});
Emitted when all products scraped by category.
Example
// 'completed' event handler
scraper.on("completed", (info) => {
console.log(info);
});
Emitted when scraper finished
Example
// 'finished' event handler
scraper.on("finished", (info) => {
console.log(info);
});
Emitted if any errors occured.
Example
// Error handler
scraper.on("error", (error) => {
console.error(error);
});