【问题标题】:i want download files with python using wget(FTP). but error occured. please help to download我想使用 wget(FTP) 用 python 下载文件。但发生错误。请帮忙下载
【发布时间】: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


    【解决方案1】:

    解码后

    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
    

    ftp      ftp      382663848 Jan 02  2021 hycom_GLBy0.08_930_2021010112_t000_ice.nc
    

    这显然是不合法的ftp 地址。你需要改变你的代码,这样它就可以了

    ftp://ftp.hycom.org/datasets/GLBy0.08/expt_93.0/data/hindcasts/2021/hycom_GLBy0.08_930_2021010112_t000_ice.nc
    

    我建议暂时使用print(url_full) 替换wget.download(url_full),然后应用更改以获得所需的输出,然后恢复为wget.download(url_full)

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多