【问题标题】:download a list of links with reptitive names with wget使用 wget 下载具有重复名称的链接列表
【发布时间】:2021-07-18 18:35:43
【问题描述】:

我有一个链接列表,但有些链接具有相同名称的不同文件。这是我的to_download.txt 文件的 sn-p:

https://www.url.domain/world/2000/may/15/one
https://www.url.domain/world/2000/nov/07/two
https://www.url.domain/world/2000/nov/17/three
https://www.url.domain/world/2000/apr/17/two
https://www.url.domain/world/2000/feb/13/one
https://www.url.domain/world/2000/jun/26/three
https://www.url.domain/world/2000/apr/25/one

当我使用wget -i /to_download.txt 时,对于具有重复文件名的URL,只有一个文件(一个one、一个two、一个three,等等)

【问题讨论】:

    标签: download wget


    【解决方案1】:

    因为您正在覆盖文件。你不能有两个同名的文件。您可以为每个月或任何模式创建单独的文件夹。

    【讨论】:

    • 但问题是:有没有办法避免这种情况而不为每个目录创建不同的目录?我找到了这个答案 (askubuntu.com/questions/584039/…),但它没有帮助,因为我需要查看我已经下载了哪个链接来更新 to_download.txt 文件。
    【解决方案2】:

    这就是我最终所做的。假设所有链接都在一个名为 l 的列表中:

    for url in l:
        n = url.split('/')
        name = n[-1] + '_' + n[-2] + '_' + n[-3] + '_' + n[-4]
        os.system('wget ' + url + ' -O ' + name)
    

    我认为这不是最好的解决方案,但它解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多