如果不是404,卷曲仅保存

The*_*mlt 0 python curl download

我正在写一个python程序,用于下载我学校学生的一些照片.

这是我的代码:`

import os
count = 0
max_c = 1000000
while max_c >= count:
    os.system("curl http://www.tjoernegaard.dk/Faelles/ElevFotos/"+str(count)+".jpg > "+str(count)+".jpg")
    count=count+1
Run Code Online (Sandbox Code Playgroud)

`

问题是我只想保存jpg,如果图像存在于服务器上(不是404),并且由于我没有服务器上的所有图像名称,我必须发送0和0之间的所有图像的请求1000000,但不存在0到1000000之间的所有图像.所以我只想保存图像,如果它存在于服务器上.我该怎么做(ubuntu)?

先感谢您

Luc*_*ila 11

您可以使用"-f"arg静默失败(不输出HTTP错误),例如:

curl -f site.com/file.jpg