unix - 在使用 Scraper wget 下载图像之前查找文件大小
问题描述
我试图在我的 wget 实际下载之前获得图像/视频大小。有没有办法获取大小并将其保存到变量中?
我试图在网上找到这个,但是,我找不到任何解决方案。
解决方案
使用该--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 $2}' output.txt
推荐阅读
- c# - 我需要通过解析 Json 后得到的循环计算值的总数,但不能使其与控制台应用程序一起使用)
- c++ - Doxygen - 如何在不生成图表的情况下生成文本调用关系结果
- c# - UniRx 中的 UpdateAsObservable() 与 EveryUpdate()?
- java - Xstream.toXML() XMLGregorianCalendar 不应有子元素
- javascript - MongoDB mapreduce而不是聚合
- python - Django从多个数据库中读写
- spring - 将 elasticsearch 从 5.6.8 更新到 6.2.3
- linux - 将错误重定向到一个文件,将标准输出重定向到另一个函数,然后再重定向到另一个文件
- java - 允许长度至少为 8 但不允许长度为 16 的字符串的正则表达式模式
- java - 为什么我的实体无法与 SpringBoot 一起使用,尽管它可以在没有 SpringBoot 的情况下使用