Last active
January 9, 2021 14:55
-
-
Save jacKlinc/7ba23c9d4a1e8600b74f20de0977d4f3 to your computer and use it in GitHub Desktop.
Search for images using contextual image search API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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