错误:[标签] [WinError2]
系统找不到指定的文件。 (您需要在此处添加更多信息,以便其他人可以了解您并为您提供帮助!)
代码:
import os
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
from msrest.authentication import CognitiveServicesCredentials
import urllib.request
subscription_key="5fcf9a36db0e4b2792e6fd39fddbbcb0"
search_term = "Alan Alda"#this was an name
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
image_results=client.images.search(query=search_term)
if image_results.value:
for i in range(len(image_results.value)):
image = image_results.value[i]
try:
f = open(search_term+'.jpg','wb')
f.write(requests.get(image.content_url).content)
f.close()
print(search_term+" Found")
break
except:
f.close()
print("Not Found")
os.remove(search_term+'.jpg')