From 743fc6f2581638a8c0640b397adfcc4bf43f99b4 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 24 Oct 2020 20:22:48 +0200 Subject: [PATCH] Add option to specify the id of a "seller" to show prices from this seller and not the "amazon" or "cheapest" price (cherry picked from commit ba0b635e30360b040e5723b9b6ce5d65876bbaca) --- README.md | 4 +++- bin/cli.js | 5 +++++ lib/Amazon.js | 5 ++++- lib/index.js | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e90fb2f..aebd00d 100755 --- a/README.md +++ b/README.md @@ -96,7 +96,9 @@ Options: blocking from the amazon side [boolean] [default: false] --user-agent Set custom user-agent [string] [default: ""] --timeout, -t Timeout between requests. Timeout is set in mls: 1000 mls = 1 - + --seller Allows to set the seller-id (A....) to limit searches to + products offered by this seller and show prices of this seller + [string] [default: ""] Examples: amazon-buddy products -k 'Xbox one' diff --git a/bin/cli.js b/bin/cli.js index f99ef62..a244d70 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -137,6 +137,11 @@ require('yargs') type: 'number', describe: 'Timeout between requests. Timeout is set in mls: 1000 mls = 1 second', }, + seller: { + default: '', + type: 'string', + describe: 'Allows to set the seller-id (A....) to limit searches to products offered by this seller and show prices of this seller', + }, }) .check((argv) => { if (['products', 'reviews', 'asin', 'categories', 'countries'].indexOf(argv['_'][0]) === -1) { diff --git a/lib/Amazon.js b/lib/Amazon.js index d272d74..7d68560 100644 --- a/lib/Amazon.js +++ b/lib/Amazon.js @@ -36,6 +36,7 @@ class AmazonScraper { asyncTasks, reviewFilter, referer, + seller, }) { this.asyncTasks = asyncTasks; this.asyncPage = 1; @@ -71,6 +72,7 @@ class AmazonScraper { this.initTime = Date.now(); this.ua = ua || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36'; this.reviewFilter = reviewFilter; + this.seller = seller; } /** @@ -247,7 +249,7 @@ class AmazonScraper { console.log(`Result was saved to: ${this.fileName}`); } return { - ...(this.scrapeType === 'products' ? { totalProducts: this.totalProducts, category: this.productSearchCategory } : {}), + ...(this.scrapeType === 'products' ? { totalProducts: this.totalProducts, category: this.productSearchCategory, seller: this.seller } : {}), ...(this.scrapeType === 'reviews' ? { ...this.reviewMetadata } : {}), result: this.collector, }; @@ -386,6 +388,7 @@ class AmazonScraper { ? { k: this.keyword, ...(this.productSearchCategory ? { i: this.productSearchCategory } : {}), + ...(this.seller ? { me: this.seller, m: this.seller } : {}), ...(page > 1 ? { page, ref: `sr_pg_${page}` } : {}), } : {}), diff --git a/lib/index.js b/lib/index.js index 31d3103..7760d5d 100755 --- a/lib/index.js +++ b/lib/index.js @@ -24,6 +24,7 @@ const INIT_OPTIONS = { filterByStar: '', formatType: 'all_formats', }, + seller: '', }; exports.products = async (options) => {