代码参考,出事自己负责

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import urllib.request
import time
import random
j = 0
# 获取10张图片
while j < 10:
order_number = lambda : int(round(time.time() * 1000 * 1000)) # 设置图片随机id
t = random.randint(1, 3) # 设置随机延时
response = urllib.request.urlopen('https://api.ixiaowai.cn/api/api.php') # 获取请求图片api
cat_img = response.read() # 保存图片
time.sleep(t) # 随机延时
print("成功获取:"+str(order_number()))
j = j + 1
DownloadPath = "D:/img/" # 自定义下载路径,必须以“ / ”必须结尾
with open(DownloadPath + str(order_number())+".jpg", "wb") as f:
f.write(cat_img)
print("下载完成")