@@ -31,7 +31,7 @@ let searchId;
3131
3232{
3333 console . log ( "getJson async await" ) ;
34- const page1 = await getJson ( "google" , params ) ;
34+ const page1 = await getJson ( { engine : "google" , ... params } ) ;
3535 searchId = page1 [ "search_metadata" ] [ "id" ] ;
3636 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
3737 const page2 = await page1 . next ?. ( ) ;
@@ -40,7 +40,7 @@ let searchId;
4040
4141{
4242 console . log ( "getJson callback" ) ;
43- getJson ( "google" , params , ( page1 ) => {
43+ getJson ( { engine : "google" , ... params } , ( page1 ) => {
4444 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
4545 page1 . next ?. ( ( page2 ) => {
4646 if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
@@ -51,6 +51,34 @@ let searchId;
5151{
5252 console . log ( "getJson using global config" ) ;
5353 config . api_key = apiKey ;
54+ const page1 = await getJson ( { engine : "google" , q : "Coffee" } ) ;
55+ if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
56+ const page2 = await page1 . next ?. ( ) ;
57+ if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
58+ }
59+
60+ {
61+ console . log ( "getJson (old API) async await" ) ;
62+ const page1 = await getJson ( "google" , params ) ;
63+ searchId = page1 [ "search_metadata" ] [ "id" ] ;
64+ if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
65+ const page2 = await page1 . next ?. ( ) ;
66+ if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
67+ }
68+
69+ {
70+ console . log ( "getJson (old API) callback" ) ;
71+ getJson ( "google" , params , ( page1 ) => {
72+ if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
73+ page1 . next ?. ( ( page2 ) => {
74+ if ( ! page2 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
75+ } ) ;
76+ } ) ;
77+ }
78+
79+ {
80+ console . log ( "getJson (old API) using global config" ) ;
81+ config . api_key = apiKey ;
5482 const page1 = await getJson ( "google" , { q : "Coffee" } ) ;
5583 if ( ! page1 [ "organic_results" ] ) throw new Error ( "No organic results" ) ;
5684 const page2 = await page1 . next ?. ( ) ;
@@ -84,6 +112,16 @@ let searchId;
84112
85113{
86114 console . log ( "getHtml" ) ;
115+ const html = await getHtml ( { engine : "google" , ...params } ) ;
116+ if ( html . length < 1000 ) throw new Error ( "Incorrect HTML" ) ;
117+
118+ getHtml ( { engine : "google" , ...params } , ( html ) => {
119+ if ( html . length < 1000 ) throw new Error ( "Incorrect HTML" ) ;
120+ } ) ;
121+ }
122+
123+ {
124+ console . log ( "getHtml (old API)" ) ;
87125 const html = await getHtml ( "google" , params ) ;
88126 if ( html . length < 1000 ) throw new Error ( "Incorrect HTML" ) ;
89127
0 commit comments