这应该做的伎俩,虽然我假定
urls.txt文件只包含的URL。没有
url:前缀。
import osimport urllibDOWNLOADS_DIR = '/python-downloader/downloaded'# For every line in the filefor url in open('urls.txt'): # Split on the rightmost / and take everything on the right side of that name = url.rsplit('/', 1)[-1] # Combine the name and the downloads directory to get the local filename filename = os.path.join(DOWNLOADS_DIR, name) # Download the file if it does not exist if not os.path.isfile(filename): urllib.urlretrieve(url, filename)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)