Bing provides a search API by which you can use the power of bing search in your own application. The base URL for the search API is:
https://api.cognitive.microsoft.com/bing/v7.0/search
The code to integrate the API using Express and Node JS is:
var express = require('express');
var path = require('path');
var app = express();
var request = require('request');
// The main search function
var bing_web_search = function (search, callback) {
console.log('Searching the Web for: ' + search);
var options = {
method: 'GET',
url: 'https://api.cognitive.microsoft.com/bing/v7.0/search',
qs: {
q: search
},
headers:
{
'ocp-apim-subscription-key': '<YOUR_SUBSCRIPTION_API_KEY>'
}
};
request(options, function (error, response, body) {
callback(error, body);
});
};
app.get('/', function (req, res) {
bing_web_search('<YOUR_SEARCH_QUERY>', function(error, body) {
if (!error) {
res.send(body);
} else {
throw new Error(error);
}
});
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Code language: JavaScript (javascript)
The API Subscription Key can be created at the website:
https://azure.microsoft.com/en-in/services/cognitive-services/bing-web-search-api/
If you want more results, then you can use pagination by adding two query params:
1. count: specifies the number of results to return in the response
2. offset: specifies the number of results to skip