首先定义文件下载路径,文件名
import os
from six.moves import urllib
import zipfile
DATA_URL = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00240/UCI%20HAR%20Dataset.zip'
DATA_DIR = './dataset/'
DATA_NAME = 'UCI HAR Dataset.zip'
filename = DATA_NAME
filepath = os.path.join(DATA_DIR, filename)
下载文件:
filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath)
解压文件:
with zipfile.ZipFile(filepath, 'r') as zip:
zip.extractall(DATA_DIR)