微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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)

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

,

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。