wget - wget 中的递归下载是如何工作的?

标签 wget utility

wget 用于镜像站点,但我想知道该实用程序如何下载域的所有 URL。

wget -r www.xyz.com

wget如何下载域xyz的所有URL?它是否访问索引页面并解析它并像爬虫一样提取链接?

最佳答案

简短回答:通常,是的,Wget 会抓取所有 URL,但有一些异常(exception):

  • robots.txt 阻止的 URL
  • 该网站包含比默认抓取深度更深的 URL
  • 使用旧版本的 Wget 在某些 CSS 情况下可能无法检索所有文件

  • 至于起点,Wget 只是从你给它的任何 URL 开始,在这种情况下 www.xyz.com .由于大多数 Web 服务器软件在未指定页面时都会返回索引页面,因此 Wget 接收索引页面以开始。
    细节
    男人为GNU Wget 1.17.1 :

    Wget can follow links in HTML, XHTML, and CSS pages ... This is sometimes referred to as "recursive downloading."


    但补充说:

    While doing that, Wget respects the Robot Exclusion Standard (/robots.txt).


    所以如果 /robots.txt指定不索引 /some/secret/page.htm当然,默认情况下这将被排除,与尊重 robots.txt 的任何其他爬虫相同.
    此外,存在默认深度限制:

    -r

    --recursive

    Turn on recursive retrieving. The default maximum depth is 5.


    因此,如果由于某种原因碰巧有比 5 更深的链接,为了满足您最初的捕获愿望 all URLs您可能想使用 -l选项,例如 -l 6去六深:

    -l depth

    --level=depth

    Specify recursion maximum depth level depth.


    另外,请注意早期版本的 Wget 在处理 CSS 中的资源时遇到问题,而这些资源又由 @import url 链接。 ,如报告:wget downloads CSS @import, but ignores files referenced within them .但是他们没有说他们使用的是什么版本,我还没有测试最新版本。我当时的解决方法是手动找出丢失的 Assets ,并专门为那些丢失的 Assets 编写单独的 Wget 命令。

    关于wget - wget 中的递归下载是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36292939/

    相关文章:

    Javascript 到 "export"所有 cookies?

    ruby - 如何从指定的 URL 将网页下载到单个文件中?

    html - 如果 wget 中使用了 --html-extension,那么 --no-clobber 仍然会覆盖文件吗?

    swift - 将 Sprite 套件用于实用程序应用程序?

    shell - 用于检查修改键是否被按下的 Ubuntu shell 实用程序

    java - Crap4j libClassPath 作为路径引用

    linux - wget 强制重试直到有连接

    url - wget with sleep 进行友好爬行

    c++ - 记录函数调用的工具?

    hadoop - 将数据推送到 HDFS 的实用程序