The Search API endpoint: https://seo-api.p.rapidapi.com/v1/search/{query
For search the minimum query must have the q
parameter. The best module to encode the query parameters is urllib.
The News API endpoint : hhttps://seo-api.p.rapidapi.com/v1/news/{query
This tutorial will be using Python3.5.
This example is a simple search for the keyword “president election”. The query should be properly url encoded. So the query will end up being q=president+election
python script:
import urllib
import requests
headers = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host" :"seo-api.p.rapidapi.com"
}
query = {
"q": "president election"
}
resp = requests.get("https://seo-api.p.rapidapi.com/v1/search/" + urllib.parse.urlencode(query), headers=headers)
results = resp.json()
print(results)
To specify the number of results to return specify the query parameter num
. To return 50 results use num=50
. To return 100 use num=100
. The default is 10 and the maximum is 100.
Python script to return the top 75 results:
import urllib
import requests
headers = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host" :"seo-api.p.rapidapi.com"
}
query = {
"q": "president election",
"num": 75
}
resp = requests.get("hhttps://seo-api.p.rapidapi.com/v1/search/" + urllib.parse.urlencode(query), headers=headers)
results = resp.json()
print(results)
Python script to return results in French
import urllib
import requests
headers = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host" :"seo-api.p.rapidapi.com"
}
query = {
"q": "president election",
"lr": "lang_fr"
}
resp = requests.get("https://seo-api.p.rapidapi.com/v1/search/" + urllib.parse.urlencode(query), headers=headers)
results = resp.json()
print(results)
To limit the search results from a certain location use cr
. For example limit the results in the Australia use cr=AU
. Or to limit the results in Canada use cr=CA
.
Python script to return results in Germany
import urllib
import requests
headers = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host" :"seo-api.p.rapidapi.com"
}
query = {
"q": "president election",
"cr": "DE"
}
resp = requests.get("https://seo-api.p.rapidapi.com/v1/search/" + urllib.parse.urlencode(query), headers=headers)
results = resp.json()
print(results)
All these parameters can be combined to perform advance queries.
Python script to query top 100 results for the keyword “coffee” in Spain
import urllib
import requests
headers = {
"x-rapidapi-key": "YOUR_API_KEY",
"x-rapidapi-host" :"seo-api.p.rapidapi.com"
}
query = {
"q": "coffee",
"cr": "ES",
"num": 100
}
resp = requests.get("https://seo-api.p.rapidapi.com/v1/search/" + urllib.parse.urlencode(query), headers=headers)
results = resp.json()
print(results)
The documentation for Googio is also powering this Google Search API.
Use this guide by Moz for more advance Google Search Parameters