Skip to content

Commit 50c38f1

Browse files
committedJun 10, 2022
Allow multi-countries
1 parent bd5611d commit 50c38f1

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed
 

‎bin/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ require('yargs')
6161
},
6262
country: {
6363
alias: 'c',
64-
default: 'us',
64+
default: '',
6565
type: 'string',
66-
describe: 'Country of proxies location'
66+
describe: 'Country of proxies location (default: all possible countries)'
6767
}
6868
})
6969
.check(argv => {

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scrapingant/amazon-proxy-scraper",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "Amazon products scraper by keyword with using ScrapingAnt API",
55
"main": "index.js",
66
"bin": {

‎products-scraper.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ProductsScraper {
2323
this.numberOfProducts = parseInt(number) || CONSTANTS.defaultItemLimit;
2424
this.currentSearchPage = 1;
2525
this.saveToFile = save || false;
26-
this.country = country || 'us';
26+
this.country = country;
2727
this.progressBar = showProgress ? new cliProgress.SingleBar({
2828
format: `Amazon Scraping: ${this.keyword} | {bar} | {percentage}% - {value}/{total} Products || ETA: {eta}s`,
2929
}, cliProgress.Presets.shades_classic) : null;
@@ -76,10 +76,12 @@ class ProductsScraper {
7676
}
7777

7878
checkForCountry() {
79-
this.country = this.country.toLowerCase();
79+
if (this.country) {
80+
this.country = this.country.toLowerCase();
8081

81-
if (!CONSTANTS.supported_countries.includes(this.country)) {
82-
throw `Not supported country. Please use one from the following: ${CONSTANTS.supported_countries.join(", ")}`;
82+
if (!CONSTANTS.supported_countries.includes(this.country)) {
83+
throw `Not supported country. Please use one from the following: ${CONSTANTS.supported_countries.join(", ")}`;
84+
}
8385
}
8486
}
8587

@@ -137,9 +139,10 @@ class ProductsScraper {
137139
for (let i = 0; i < CONSTANTS.limit.retry; i++) {
138140
try {
139141
// Retry for any network or accessibility cases
142+
const params = this.country ? { proxy_country: this.country } : {};
140143
const response = await retry((attempt) => this.client.scrape(
141144
`${this.host}/s?${queryParams}`,
142-
{ proxy_country: this.country }
145+
params
143146
).catch(attempt), { retries: CONSTANTS.limit.retry });
144147

145148
const pageBody = response.content;

0 commit comments

Comments
 (0)
Please sign in to comment.