11

I am looking for a Google search API wrapper to be used in Node.js, I have searched around but haven't found something updated and fully baked. Can anyone please recommend something working? Thanks

user971956
  • 3,088
  • 7
  • 30
  • 47

5 Answers5

7

Why aren't you using node client lib for Google APIs? https://github.com/google/google-api-nodejs-client

var googleapis = require('googleapis');
googleapis.discover('customsearch', 'v1').execute(function(err, client) {
  // set api key
  client.withApiKey('...');
  client.search.cse.list({ q: '...' }).execute(console.log);
});
Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
  • 1
    I don't see any documentation that cse is supported by google's node wrapper. Is it? – kayaker243 Sep 16 '13 at 22:16
  • To specify a custom search engine, specify a `cx` property in the config object, next to the `q` property. A full example is available in the GitHub repo : https://github.com/google/google-api-nodejs-client/blob/master/examples/customsearch.js – Louis Ameline Mar 10 '14 at 08:57
3

I'm assuming you are not referring to the deprecated Google Web Search API...

The Google Custom Search API is a RESTful API. This means that you can easily access it without a specialized wrapper.

There are a couple of modules that make this easier. The one I usually use is the request module, which lets you make HTTP requests very simply.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Steve Campbell
  • 3,385
  • 1
  • 31
  • 43
3

I just used node-google-images and it worked right away in less than 2 minutes:

https://github.com/vdemedes/node-google-images

Just call

npm install google-images

and then

client = require( 'google-images' );

client.search( 'Chicken Teriyaki', function (err, images) {
    console.log(images)
});

will return

[ { width: '1920', height: '1280', url: 'http://www.springkitchenrestaurant.com/Chicken_Teriyaki.jpg', writeTo: [Function] }]

(actually, it will return 4 results but stackoverflow prevents me from posting more than 2 links... - you get the gist!)

Nico
  • 4,248
  • 1
  • 20
  • 19
  • It is giving only one image data, How can I get more than 10 using this? Or I want an array of image data. Can you plz help me how can get an array of images of the search keyword. – Shubham Verma Nov 13 '17 at 09:45
  • I think it was depreciated a while back. I use yahoo image search now. It costs a little but works decently. https://yboss.yahooapis.com/ysearch/images – Nico Nov 13 '17 at 15:11
1

You can use jsearch module. Install with:

npm install jsearch

Usage:

js.google('queryStringYouWant',10,function(response){
    console.log(response) // for Google results 
})
Floern
  • 33,559
  • 24
  • 104
  • 119
hasan
  • 29
  • 2
  • 9
0

You can use a third-party service like SerpApi with its Node.js library to scrape Google and get back structured JSON.

To install it:

npm install google-search-results-nodejs

Code example:

var gsr = require('GoogleSearchResults')
let serp = new gsr.GoogleSearchResults()
query_params = {
  q: "query",
  google_domain: "Google Domain", 
  location: "Location Requested", 
  device: device,
  hl: "Google UI Language",
  gl: "Google Country",
  safe: "Safe Search Flag",
  num: "Number of Results",
  start: "Pagination Offset",
  serp_api_key: "demo"
}

callback = function(data) {
 console.log(data)
}

// Show result as JSON
serp.json(query_params, callback)

// Show results as JSON with Images
serp.jsonWithImages(query_params, callback)

// Show result as HTML file
serp.html(query_params, callback)
Hartator
  • 5,029
  • 4
  • 43
  • 73