Skip to content

Instantly share code, notes, and snippets.

@jacKlinc
Last active January 9, 2021 14:55
Show Gist options
  • Save jacKlinc/7ba23c9d4a1e8600b74f20de0977d4f3 to your computer and use it in GitHub Desktop.
Save jacKlinc/7ba23c9d4a1e8600b74f20de0977d4f3 to your computer and use it in GitHub Desktop.
Search for images using contextual image search API
def search_contextual(key, term, max_images: int=100, **kwargs):
url = "https://contextualwebsearch-websearch-v1.p.rapidapi.com/api/Search/ImageSearchAPI"
querystring = {"q": term, "pageNumber": "1", "pageSize": max_images, "autoCorrect": "true"}
headers = {
'x-rapidapi-key': key,
'x-rapidapi-host': "contextualwebsearch-websearch-v1.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring).json()
images=[]
for image in response["value"]:
images.append(image["url"])
return images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment