【发布时间】:2022-01-21 21:56:30
【问题描述】:
我想在 ftp 中下载“*_ice.nc”文件。所以..
图书馆
import wget
import math
import re
from urllib import request
地址和文件列表
url = "ftp://ftp.hycom.org/datasets/GLBy0.08/expt_93.0/data/hindcasts/2021/" #url
html = request.urlopen(url) #open url
html_contents = str(html.read().decode("cp949"))
url_list = re.findall(r"(ftp)(.+)(_ice.nc)", html_contents)
循环下载
for url in url_list: #loop
url_full="".join(url) #tuple to string
file_name=url_full.split("/")[-1]
print('\nDownloading ' + file_name)
wget.download(url_full) #down with wget
但是错误消息是这样发生的 (ValueError:未知的url类型:'ftp%20%20%20%20%20%20ftp%20%20%20%20%20%20382663848%20Jan%2002%20%202021%20hycom_GLBy0.08_930_2021010112_t000_ice.nc')
我能得到一些帮助吗?
【问题讨论】:
标签: python-3.x url download ftp wget