作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 Files.txt
,其中包含 Excel 文件的 URL 列表:
http://www.bcheadset.ca/applicant.xlsx
http://www.bcheadset.ca/fte.xlsx
http://www.iutox.org/TRTF_Matrix2012_Oct.xlsx
http://www.journalprices.com/2013_FinalSummaryForWeb.xlsx
http://www.camts.org/7__2013_Aircraft_Checklist.xlsx
http://www.nanotr11.org/poster_program.xlsx
http://www.vliruos.be/media/6352100/nss2015_annex_3_budget.xlsx
...
我想做的是下载(通过 wget)大于 10Mo
的文件。
要在下载文件之前验证文件是否大于 10Mo
,我们可以使用 curl --head
。例如,curl --head http://www.bcheadset.ca/fte.xlsx
返回
HTTP/1.1 200 OK
Content-Length: 3158847
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Last-Modified: Mon, 27 Jul 2015 22:16:45 GMT
Accept-Ranges: bytes
ETag: "ffb49fecb9c8d01:c05"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 06 Oct 2015 15:14:27 GMT
并且从Content-Length
,我们可以验证它大于10Mo
。
我的问题是如何通过一段 Bash
或 Perl
将其自动化。特别是我不知道如何提取 Content-Length
并进行比较...
有人能帮忙吗?
最佳答案
您可以使用 LWP
和 perl
并发送 HEAD
请求,获取响应 header 。像这样:
#!/usr/bin/env perl
use strict;
use warnings;
use LWP;
use Data::Dumper;
my $request = HTTP::Request -> new ( HEAD => 'http://www.google.com' );
my $agent = LWP::UserAgent -> new;
my $response = $agent -> request ( $request );
print $response -> header ( 'Content-Length');
然后使用 LWP 执行 GET
而不是 HEAD
您想要该文件。
关于bash - 下载大于一定大小的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32973928/
我正在尝试开发右边框/Angular 具有特定 Angular (30°) 的表格。我见过一些类似的解决方案,但它们都无法在一定程度上发挥作用。如果我想从 30° 改变到 20°,我不想花太多力气。
我是一名优秀的程序员,十分优秀!