代码:
import urllib.request from httpx import request import requests import os from pexels_api import API PEXELS_API_KEY = '563492ad6f917000010000013810554063464054b9a100b44469eff2' api = API(PEXELS_API_KEY) api.search('kitten', page=1, results_per_page=5) photos = api.get_entries() for photo in photos: #print('Photographer: ', photo.photographer) #print('Photo url: ', photo.url) print('Photo original size: ', photo.original) url=photo.original img=requests.get(url) print("下载图片地址:"+url) img_name=url.split('/')[5] print("下载图片名字:"+img_name) save_file_name=os.getcwd()+'\images\'+img_name with open(save_file_name,'wb') as f: f.write(img.content) print("下载结束n")