@@ -23,7 +23,7 @@ class ProductsScraper {
23
23
this . numberOfProducts = parseInt ( number ) || CONSTANTS . defaultItemLimit ;
24
24
this . currentSearchPage = 1 ;
25
25
this . saveToFile = save || false ;
26
- this . country = country || 'us' ;
26
+ this . country = country ;
27
27
this . progressBar = showProgress ? new cliProgress . SingleBar ( {
28
28
format : `Amazon Scraping: ${ this . keyword } | {bar} | {percentage}% - {value}/{total} Products || ETA: {eta}s` ,
29
29
} , cliProgress . Presets . shades_classic ) : null ;
@@ -76,10 +76,12 @@ class ProductsScraper {
76
76
}
77
77
78
78
checkForCountry ( ) {
79
- this . country = this . country . toLowerCase ( ) ;
79
+ if ( this . country ) {
80
+ this . country = this . country . toLowerCase ( ) ;
80
81
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
+ }
83
85
}
84
86
}
85
87
@@ -137,9 +139,10 @@ class ProductsScraper {
137
139
for ( let i = 0 ; i < CONSTANTS . limit . retry ; i ++ ) {
138
140
try {
139
141
// Retry for any network or accessibility cases
142
+ const params = this . country ? { proxy_country : this . country } : { } ;
140
143
const response = await retry ( ( attempt ) => this . client . scrape (
141
144
`${ this . host } /s?${ queryParams } ` ,
142
- { proxy_country : this . country }
145
+ params
143
146
) . catch ( attempt ) , { retries : CONSTANTS . limit . retry } ) ;
144
147
145
148
const pageBody = response . content ;
0 commit comments