繁体   English   中英

Wget使用文件中的Lins下载文件并重命名

[英]Wget download files using lins in a file and rename

我的文件的链接用\\n分隔。 而且我还有一个文件,其中包含每个链接的新名称。 有没有一种方法可以下载文件并仅使用wget重命名它们?

之所以这样做,是因为我从网页中获取了这些链接,该链接的末尾是文件名的哈希,但是文件的实际名称存储在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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM