簡體   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