Google search API wrapper for Node.js
Asked Answered
P

5

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

Protohuman answered 18/4, 2012 at 12:12 Comment(1)
Use serphouse.com to search on Google via API and get data in JSON structureSteenbok
F
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);
});
Frazer answered 9/3, 2013 at 20:22 Comment(2)
I don't see any documentation that cse is supported by google's node wrapper. Is it?Boucher
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 : github.com/google/google-api-nodejs-client/blob/master/examples/…Pelagia
R
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.

Robrobaina answered 19/4, 2012 at 21:39 Comment(0)
P
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!)

Purehearted answered 15/8, 2015 at 0:56 Comment(2)
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.Merlinmerlina
I think it was depreciated a while back. I use yahoo image search now. It costs a little but works decently. yboss.yahooapis.com/ysearch/imagesPurehearted
J
1

You can use jsearch module. Install with:

npm install jsearch

Usage:

js.google('queryStringYouWant',10,function(response){
    console.log(response) // for Google results 
})
Jessabell answered 8/4, 2016 at 18:0 Comment(1)
What is the 10? is it a number of urls what I get? I think it is not giving the relevant URL what I want to search.Merlinmerlina
E
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)
Eagle answered 9/4, 2018 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.