@@ -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