File tree 1 file changed +22
-5
lines changed
1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,9 @@ class ProductsScraper {
23
23
24
24
async startScraping ( ) {
25
25
this . checkForCountry ( ) ;
26
-
27
- if ( this . numberOfProducts > CONSTANTS . limit . product ) {
28
- this . numberOfProducts = CONSTANTS . limit . product ;
29
- console . info ( `Setting number to MAXIMUM available (${ CONSTANTS . limit . product } ) because of exceeding limit` ) ;
30
- }
26
+ this . checkForApiKey ( ) ;
27
+ this . checkForKeyword ( ) ;
28
+ this . checkForProductsNumber ( ) ;
31
29
32
30
while ( true ) {
33
31
if ( this . alreadyScrappedProducts . length >= this . numberOfProducts ) {
@@ -80,6 +78,25 @@ class ProductsScraper {
80
78
}
81
79
}
82
80
81
+ checkForApiKey ( ) {
82
+ if ( ! this . apiKey ) {
83
+ throw `No RapidAPI apiKey. Please refer to https://rapidapi.com/okami4kak/api/scrapingant for getting yours.` ;
84
+ }
85
+ }
86
+
87
+ checkForKeyword ( ) {
88
+ if ( ! this . keyword ) {
89
+ throw `No keyword for search. Please specify it..` ;
90
+ }
91
+ }
92
+
93
+ checkForProductsNumber ( ) {
94
+ if ( this . numberOfProducts > CONSTANTS . limit . product ) {
95
+ this . numberOfProducts = CONSTANTS . limit . product ;
96
+ console . info ( `Setting number to MAXIMUM available (${ CONSTANTS . limit . product } ) because of exceeding limit.` ) ;
97
+ }
98
+ }
99
+
83
100
async getCurrentPageData ( ) {
84
101
const queryParams = querystring . encode ( {
85
102
k : this . keyword ,
You can’t perform that action at this time.
0 commit comments