Wget在文件中使用lins下载文件并重命名

Wget download files using lins in a file and rename

我有文件 link 由 \n 分隔。 我还有一个文件,其中包含每个 link 的新名称。 有没有办法只使用 wget 下载文件并重命名它们?

我这样做是因为我从 link 有 最后是文件名的散列,但文件的实际名称存储在 html 元素的描述中。

Python 解决方案:

#-*- coding:utf-8 -*-
import os
import urllib2

with open('path_to_your_hash_url', 'r') as fh:
    url_to_be_download = fh.read().split("\n")

with open('path_to_your_FileNames', 'r') as fh:
    fileNames = fh.read().split('\n')

siteurl = 'http://whatever.com/'  #path to your site


downloadFolder = r'YourDownloadFile folder'


for i, url in enumerate(url_to_be_download):
    location = os.path.join(downloadFolder, url_to_be_download[i])
    with open(newloc,"w") as fh:
        full_url = siteurl+ url
        ufile = urllib2.urlopen(full_url).read()
        fh.write(ufile)