使用 wget 下载具有重复名称的链接列表

问题描述

我有一个链接列表,但有些链接包含同名的不同文件。这是我的 to_download.txt 文件的片段:

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 等)

>

解决方法

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

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

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

,

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