Lately, I have been working at SerpsBot where you can consume results from Google Search and Bing search for data mining purposes or for any other use case. Today, I am going to write a tutorial on how you can develop a custom search engine for your website(s) utilizing SerpsBot API.

Why SerpsBot?

You may ask, Google offers a solution called Programmable Search Engine, then why one would use SerpsBot? The answer is, with SerpsBot, the cost is much much low as well as you don't get any limitations in terms of API calls and so on.

Getting Started

I'll be using Python and Python Requests in order to explain how you can build a custom search engine using SerpsBot. Let's get started.

Step 1: Get an API Key

First of all, you need an API key from SerpsBot. Get one by creating an account at https://app.serpsbot.com.

Once you get your API key, proceed further and start writing code. Let's get started. I assume that you have already installed Python Requests. If not, you will have to do that first.

import requests
from json.decoder import JSONDecodeError


# Define some (pseudo) constants
API_KEY='your-serpsbot-api-key-here'
SITE_DOMAIN = 'supportivehands.net'
GOOGLE_API_ENDPOINT = 'https://api.serpsbot.com/api/v1/google-serps/'
BING_API_ENDPOINT = 'https://api.serpsbot.com/api/v1/bing-serps/'

# Set some required headers
headers = {
	'Authorization': f'Bearer {API_KEY}'
}

# Construct search query
search_term = 'python'
search_query = f'site:{SITE_DOMAIN} {search_term}'
params = {
	'q': search_query,
    'page': 1
}

# Get Google search results
res = requests.get(GOOGLE_API_ENDPOINT, headers=headers, params=params)

try:
	data = res.json()
except JSONDecodeError:
	data = None

results = []
if data:
	results += list(data.get('data').get('results').get('organic'))

# Get Bing search results
res = requests.get(BING_API_ENDPOINT, headers=headers, params=params)

try:
	data = res.json()
except JSONDecodeError:
	data = None

if data:
	results += list(data.get('data').get('results').get('organic'))

That's it. The results returned for the API call will contain results for your provided website only. You can use these results for any purpose, like looping through them in an HTML template and display the results there and so on.

If you want to use search results for more than one website, simply create a list of your domains and loop through them to get results for each domain individually.

I hope this gives a basic idea on how to create a custom search engine utilizing the power of Google Search and Bing Search.