×

Custom Image Search API – Python 3.x client library

How to use Custom Image Search with Python documentation

Use Python 3.x client library to integrate News API into your Python 3.x application

import requests #install from: http://docs.python-requests.org/en/master/

#Replace the following string value with your valid X-RapidAPI-Key.
Your_X_RapidAPI_Key = "XXXXXXXXXXXXXXXXXXX";

#The query parameters: (update according to your search query)
q = "Taylor%20Swift" #the search query
pageNumber = 1 #the number of requested page
searchEngineId = "XXXX"; #the id of the custom search engine 

response=requests.get("https://custom-search.p.rapidapi.com/api/search/CustomImageSearchAPIV2?q={}&pageNumber={}&searchEngineId={}".format(q, pageNumber, searchEngineId),
headers={
"X-RapidAPI-Key": Your_X_RapidAPI_Key
}
).json()

#Get the numer of items returned
totalCount = response["totalCount"];

#Go over each resulting item
for image in response["value"]:

    # Get the image
    imageUrl = webPage["url"]
    imageHeight = webPage["height"]
    imageWidth = webPage["width"]

    # Get the image thumbail
    thumbnail = webPage["thumbnail"]
    thumbnailHeight = webPage["thumbnailHeight"]
    thumbnailWidth = webPage["thumbnailWidth"]

    #An example: Output the webpage url, title and published date:
    print("imageUrl: %s. imageHeight: %s. imageWidth: %s." % (imageUrl, imageHeight, imageWidth))