在使用 Scraper wget 下载图像之前查找文件大小
Find file size before downloading Image with Scraper wget
我试图在我的 wget 实际下载它之前获取 image/video 大小。有没有办法获取大小并将其保存到变量?
我试图在网上找到这个,但是,我无法找到任何解决方案。
使用 --spider
选项,然后将输出保存到文本文件:
$ wget --spider https://www.google.com/image.jpg > output.txt
$ wget --spider https://www.google.com/video.mp4 > output.txt
示例输出:
Spider mode enabled. Check if remote file exists.
--2016-09-16 14:23:42-- http://www.bbc.co.uk/
Resolving www.bbc.co.uk (www.bbc.co.uk)... 212.58.244.67, 212.58.246.91
Connecting to www.bbc.co.uk (www.bbc.co.uk)|212.58.244.67|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=utf-8
...
Length: 171933 (168K) [text/html] <---------- Right here is the file size
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
然后用awk
读取第10行第2个字得到文件大小:
$ awk 'fileSize==10 {print }' output.txt
我试图在我的 wget 实际下载它之前获取 image/video 大小。有没有办法获取大小并将其保存到变量?
我试图在网上找到这个,但是,我无法找到任何解决方案。
使用 --spider
选项,然后将输出保存到文本文件:
$ wget --spider https://www.google.com/image.jpg > output.txt
$ wget --spider https://www.google.com/video.mp4 > output.txt
示例输出:
Spider mode enabled. Check if remote file exists.
--2016-09-16 14:23:42-- http://www.bbc.co.uk/
Resolving www.bbc.co.uk (www.bbc.co.uk)... 212.58.244.67, 212.58.246.91
Connecting to www.bbc.co.uk (www.bbc.co.uk)|212.58.244.67|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=utf-8
...
Length: 171933 (168K) [text/html] <---------- Right here is the file size
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
然后用awk
读取第10行第2个字得到文件大小:
$ awk 'fileSize==10 {print }' output.txt