wget without any headers

戏子无情 提交于 2019-12-31 03:52:32

问题


I would like to get the files without headers. I have tried many things like

wget --header="" http://xxxxx.xxxxxx.xx

How can I get any files without headers?


回答1:


‘--header=header-line’ Send header-line along with the rest of the headers in each http request. The supplied header is sent as-is, which means it must contain name and value separated by colon, and must not contain newlines. You may define more than one additional header by specifying ‘--header’ more than once.

      wget --header='Accept-Charset: iso-8859-2' \
           --header='Accept-Language: hr'        \
             http://fly.srk.fer.hr/ Specification

of an empty string as the header value will clear all previous user-defined headers.

As of Wget 1.10, this option can be used to override headers otherwise generated automatically. This example instructs Wget to connect to localhost, but to specify ‘foo.bar’ in the Host header:

      wget --header="Host: foo.bar" http://localhost/ In versions

of Wget prior to 1.10 such use of ‘--header’ caused sending of duplicate headers.

http://www.gnu.org/software/wget/manual/html_node/HTTP-Options.html




回答2:


Could you assign the output of wget to a string, then use something else to process it to drop headers (or parse them out of the text), such as

w1=$(wget --quiet --output-document - www.example.com)
echo $w1 | grep --only-matching "<body>.*</body>"

giving (adding newlines to display nicely here):

<body> <div> <h1>Example Domain</h1> <p>This domain is established to be used for 
illustrative examples in documents. You may use this domain in examples without 
prior coordination or asking for permission.</p> <p><a href="http://www.iana.org
/domains/example">More information...</a></p> </div> </body>


来源:https://stackoverflow.com/questions/2624304/wget-without-any-headers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!