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
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);
});
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 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.
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!)
You can use jsearch module. Install with:
npm install jsearch
Usage:
js.google('queryStringYouWant',10,function(response){
console.log(response) // for Google results
})
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)
© 2022 - 2024 — McMap. All rights reserved.