You actually don't need selenium for this. You are calling a REST-API here.
Simply do something like this:
import requests
import traceback
def searchApi(query):
endpoint = "http://prod.media.jio.com/apis/common/v3.1/search/auto"
data = {
"q": query
}
try:
response = requests.post(endpoint, data=data)
if(response.status_code == 200):
for msg in response:
print(msg)
except Exception:
print(traceback.format_exc())
Usage:
searchApi("avengers")
Raw output:
{
"code": 200,
"message": "success",
"data": {
"items": [
{
"name": "avengers grimm",
"type": "Movies"
},
{
"name":"avengers endgame official trailer hindi ",
"type":"Videos"
},
{
"name":"avengers endgame official trailer",
"type":"Videos"
},
{
"name":"avengers endgame special look",
"type":"Videos"
}
.... continues
]
}
}
Alternatively, if you want to access the data-response directly.
import json
def searchApi(query):
endpoint = "http://prod.media.jio.com/apis/common/v3.1/search/auto"
data = {
"q": query
}
try:
response = requests.post(endpoint, data=data)
if(response.status_code == 200):
response = response.json()
for msg in response["data"]["items"]:
print("name: ", msg["name"], "type: ", msg["type"])
except Exception:
print(traceback.format_exc())
Formatted output msg["name"]
and msg["type"]
:
name: avengers grimm type: Movies
name: avengers endgame official trailer type: Videos
name: avengers endgame special look type: Videos
name: avengers endgame official trailer hindi type: Videos
name: the avengers earth s mightiest heroes type: TV Shows
name: marvel's avengers age of ultron type: Movies
name: marvel's avengers assemble type: TV Shows
name: marvel's avengers age of ultron official trailer hindi type: Videos
name: marvel's avengers age of ultron official trailer type: Videos
name: marvel's the avengers type: Movies
name: marvel's the avengers official trailer type: Videos
name: marvel's the avengers official trailer hindi type: Videos
name: making of south indian avengers type: Videos