Wget output document and headers to STDOUT

前端 未结 5 847
失恋的感觉
失恋的感觉 2020-12-22 18:30

I\'m trying to output the document body and its headers to STDOUT by doing

wget -S -O - http://google.com

...but it shows only the HTML docum

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 19:18

    wget -S -O - http://google.com works as expected for me, but with a caveat: the headers are considered debugging information and as such they are sent to the standard error rather than the standard output. If you are redirecting the standard output to a file or another process, you will only get the document contents.

    You can try redirecting the standard error to the standard output as a possible solution. For example, in bash:

    $ wget -q -S -O - 2>&1 | grep ...
    

    or

    $ wget -q -S -O - 1>wget.txt 2>&1
    

    The -q option suppresses the progress bar and some other annoyingly chatty parts of the wget output.

提交回复
热议问题