@@ -17,17 +17,17 @@ const params = {
1717
1818let searchId ;
1919
20- // getJson async await
2120{
21+ console . log ( "getJson async await" )
2222 const page1 = await getJson ( "google" , params ) ;
2323 searchId = page1 [ "search_metadata" ] [ "id" ] ;
2424 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
2525 const page2 = await page1 . next ?. ( ) ;
2626 if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
2727}
2828
29- // getJson callback
3029{
30+ console . log ( "getJson callback" )
3131 getJson ( "google" , params , ( page1 ) => {
3232 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
3333 page1 . next ?. ( ( page2 ) => {
@@ -36,17 +36,17 @@ let searchId;
3636 } ) ;
3737}
3838
39- // getJson using global config
4039{
40+ console . log ( "getJson using global config" )
4141 config . api_key = apiKey ;
4242 const page1 = await getJson ( "google" , { q : "Coffee" } ) ;
4343 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
4444 const page2 = await page1 . next ?. ( ) ;
4545 if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
4646}
4747
48- // getJson pagination loop (async/await)
4948{
49+ console . log ( "getJson pagination loop (async/await)" )
5050 const links = [ ] ;
5151 let page = await getJson ( "google" , params ) ;
5252 while ( page ) {
@@ -57,8 +57,8 @@ let searchId;
5757 if ( links . length < 30 ) throw new Error ( "Incorrect number of links" ) ;
5858}
5959
60- // getJson pagination loop (callback)
6160{
61+ console . log ( "getJson pagination loop (callback)" )
6262 const links = [ ] ;
6363 getJson ( "google" , params , ( page ) => {
6464 links . push ( ...page . organic_results . map ( r => r . link ) ) ;
@@ -70,8 +70,8 @@ let searchId;
7070 } ) ;
7171}
7272
73- // getHtml
7473{
74+ console . log ( "getHtml" )
7575 const html = await getHtml ( "google" , params ) ;
7676 if ( html . length < 1000 ) throw new Error ( "Incorrect HTML" ) ;
7777
@@ -80,8 +80,8 @@ let searchId;
8080 } ) ;
8181}
8282
83- // getJsonBySearchId
8483{
84+ console . log ( "getJsonBySearchId" )
8585 config . api_key = apiKey ;
8686 const json = await getJsonBySearchId ( searchId ) ;
8787 if ( ! json [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
@@ -91,8 +91,8 @@ let searchId;
9191 } ) ;
9292}
9393
94- // getHtmlBySearchId
9594{
95+ console . log ( "getHtmlBySearchId" )
9696 config . api_key = apiKey ;
9797 const html = await getHtmlBySearchId ( searchId ) ;
9898 if ( html . length < 1000 ) throw new Error ( "Incorrect HTML" ) ;
@@ -102,8 +102,8 @@ let searchId;
102102 } ) ;
103103}
104104
105- // getAccount
106105{
106+ console . log ( "getAccount" )
107107 config . api_key = apiKey ;
108108 const info = await getAccount ( ) ;
109109 if ( ! info [ "account_email" ] ) throw new Error ( "Incorrect account info" ) ;
@@ -113,8 +113,8 @@ let searchId;
113113 } ) ;
114114}
115115
116- // getLocations
117116{
117+ console . log ( "getLocations" )
118118 const locations = await getLocations ( { limit : 3 } ) ;
119119 if ( locations . length !== 3 ) throw new Error ( "Incorrect locations length" ) ;
120120
0 commit comments