使用wget获取进度条中的最后一行

时间:2018-02-01 04:09:57

标签: python python-2.7 wget

我正在尝试将wget结果STDOUT到文本文件,只是想在结果中获取进度条的最后一行。

以下是我的结果示例。

--2018-02-01 11:16:45--  http://www.stackoverflow.com/
Resolving www.stackoverflow.com (www.stackoverflow.com)... 151.101.1.69, 151.101.65.69, 151.101.129.69, ...
Connecting to www.stackoverflow.com (www.stackoverflow.com)|151.101.1.69|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://stackoverflow.com/ [following]
--2018-02-01 11:16:45--  https://stackoverflow.com/
Resolving stackoverflow.com (stackoverflow.com)... 151.101.1.69, 151.101.65.69, 151.101.129.69, ...
Connecting to stackoverflow.com (stackoverflow.com)|151.101.1.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 254160 (248K) [text/html]
Saving to: ‘/dev/null’


/dev/null             0%[                    ]       0  --.-KB/s               
/dev/null            20%[===>                ]  50.27K   248KB/s               
/dev/null            75%[==============>     ] 186.90K   464KB/s               
/dev/null           100%[===================>] 248.20K   514KB/s    in 0.5s    

2018-02-01 11:16:46 (514 KB/s) - ‘/dev/null’ saved [254160/254160]

这就是我得到的方式

wget -O /dev/null --progress=bar:force www.stackoverflow.com 2>> log_browse.txt

如何在仅显示此文件的文件中输出?

--2018-02-01 11:16:45--  http://www.stackoverflow.com/
Resolving www.stackoverflow.com (www.stackoverflow.com)... 151.101.1.69, 151.101.65.69, 151.101.129.69, ...
Connecting to www.stackoverflow.com (www.stackoverflow.com)|151.101.1.69|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://stackoverflow.com/ [following]
--2018-02-01 11:16:45--  https://stackoverflow.com/
Resolving stackoverflow.com (stackoverflow.com)... 151.101.1.69, 151.101.65.69, 151.101.129.69, ...
Connecting to stackoverflow.com (stackoverflow.com)|151.101.1.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 254160 (248K) [text/html]
Saving to: ‘/dev/null’


/dev/null           100%[===================>] 248.20K   514KB/s    in 0.5s    

2018-02-01 11:16:46 (514 KB/s) - ‘/dev/null’ saved [254160/254160]

进展的最后一行......

1 个答案:

答案 0 :(得分:0)

您可以使用tail command从底部读取文件。

{{1}}

-n 1 - >获取最后一行。您可以通过更改数字EX来改变它:使用最后两行使用-n 2