Skip to content
On this page

代码演示

python
import urllib.request
import time
import random
j = 0
# 获取100张图片
while j < 100:
    order_number = lambda : int(round(time.time() * 1000 * 1000))  # 设置图片随机id
    t = random.randint(1, 5)  # 设置随机延时
    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("下载完成")

温馨提醒

慎重使用,出事后果自负

所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自linlink~文档