【问题标题】:How to download an entire directory and subdirectories using wget?如何使用 wget 下载整个目录和子目录?
【发布时间】:2013-06-21 09:34:34
【问题描述】:

我正在尝试使用wget 下载项目的文件,因为该项目的 SVN 服务器不再运行,我只能通过浏览器访问这些文件。所有文件的基本 URL 都相同,如

http://abc.tamu.edu/projects/tzivi/repository/revisions/2/raw/tzivi/*

如何使用wget(或任何其他类似工具)下载此存储库中的所有文件,其中“tzivi”文件夹是根文件夹,并且有多个文件和子文件夹(最多 2 或 3级别)在它下面?

【问题讨论】:

  • 如果服务器没有包含您需要的所有文件链接列表的网页,您就不能这样做。
  • 你知道文件名吗?
  • 不,我不知道所有文件的名称。我尝试使用递归选项 wget,但它也不起作用。是因为服务器没有任何 index.html 文件列出所有内部链接。
  • 你试过wget的镜像选项吗?

标签: regex linux bash wget


【解决方案1】:

你可以在 shell 中使用它:

wget -r --no-parent http://abc.tamu.edu/projects/tzivi/repository/revisions/2/raw/tzivi/

参数是:

-r     //recursive Download

--no-parent // Don´t download something from the parent directory

如果您不想下载全部内容,可以使用:

-l1 just download the directory (tzivi in your case)

-l2 download the directory and all level 1 subfolders ('tzivi/something' but not 'tivizi/somthing/foo')  

等等。如果不插入-l 选项,wget 将自动使用-l 5

如果您插入-l 0,您将下载整个互联网,因为wget 将跟踪它找到的每个链接。

【讨论】:

  • 太棒了,为下一位读者简化:wget -r -l1 --no-parent http://www.stanford.edu/~boyd/cvxbook/cvxbook_additional_exercises/ 是我的答案。谢谢你的回答。
  • 我尝试使用上述命令从http://websitename.com/wp-content/uploads/2009/05 获取所有文件,但我得到的只是一个没有任何内容的index.html 文件。我想不出我错过了什么。
  • 我知道这已经很老了。但我还发现有用的是-e robots=off 开关。 ;)
  • 你为什么不删除“我忘记了重要的事情”并修复答案???
  • 我们可以在 wget 中使用 -nH 选项来防止默认情况下使用下载目录创建主机名目录。
【解决方案2】:

您可以在 shell 中使用它:

wget -r -nH --cut-dirs=7 --reject="index.html*" \
      http://abc.tamu.edu/projects/tzivi/repository/revisions/2/raw/tzivi/

参数是:

-r recursively download

-nH (--no-host-directories) cuts out hostname 

--cut-dirs=X (cuts out X directories)

【讨论】:

    【解决方案3】:

    使用命令

    wget -m www.ilanni.com/nexus/content/
    

    【讨论】:

      【解决方案4】:

      你也可以使用这个命令:

      wget --mirror -pc --convert-links -P ./your-local-dir/ http://www.your-website.com
      

      以便您获得要下载的网站的确切镜像

      【讨论】:

        【解决方案5】:

        这行得通:

        wget -m -np -c --no-check-certificate -R "index.html*" "https://the-eye.eu/public/AudioBooks/Edgar%20Allan%20Poe%20-%2"
        

        【讨论】:

          【解决方案6】:
          wget -r --no-parent URL --user=username --password=password
          

          如果你有下载的用户名和密码,最后两个选项是可选的,否则不需要。

          您还可以在链接https://www.howtogeek.com/281663/how-to-use-wget-the-ultimate-command-line-downloading-tool/中看到更多选项

          【讨论】:

            【解决方案7】:

            This link刚刚给了我最好的答案:

            $ wget --no-clobber --convert-links --random-wait -r -p --level 1 -E -e robots=off -U mozilla http://base.site/dir/
            

            工作就像一个魅力。

            【讨论】:

            • 这段代码在哪里使用?
            【解决方案8】:

            这会有所帮助

            wget -m -np -c --level 0 --no-check-certificate -R"index.html*"http://www.your-websitepage.com/dir
            

            【讨论】:

            【解决方案9】:

            试试这个工作代码 (30-08-2021):

            !wget --no-clobber --convert-links --random-wait -r -p --level 1 -E -e robots=off --adjust-extension -U mozilla "yourweb directory with in quotations"
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2015-07-16
              • 2019-05-30
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多