仅当 http status 200 与 wget 时才创建文件? [英] Only create file if http status 200 with wget?

查看:20
本文介绍了仅当 http status 200 与 wget 时才创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想办法让 wget 只在实际下载响应有效的情况下创建一个文件,这意味着没有 404 或 500 状态代码,只有 200.

I have been trying to figure out a way to make wget only create a file if the actual download response is valid, meaning no 404 or 500 status code, only 200.

但是,当使用 -O 选项(指定文件名)时,它总是会创建带有错误页面内容的文件,而且我还没有找到一种方法来指定它在收到错误信息时应忽略它404 响应头.

However, when using the -O option (to specify filename) it will always create the file, with the content of the error page, and I haven't found a way to specify that it should ignore it if it recieves a 404 response-header.

我需要检查退出代码并通过管道传输输出还是有更好的替代方法?

Do I need to check the exit-code and pipe the output or is there a better alternative?

推荐答案

也许这是唯一的答案,除了修补 wget(一个有效的选项):

Perhaps this is the only answer, other than patching wget (a valid option):

wget -O somefile.html http://example.com/ || rm somefile.html

这篇关于仅当 http status 200 与 wget 时才创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆