这里有新的(newb)python用户!快速提问,希望基本水平,与之合作 urllib.request.urlretrieve。我无法弄清楚为什么下面的代码返回一个HTML文件(保存为.zip)而不是实际的zip文件。任何帮助都将非常感谢!!!
import os
import zipfile
import urllib.request, urllib.parse, urllib.error
DOWNLOAD_ROOT = "https://www.kaggle.com/annavictoria/speed-dating-experiment/downloads/"
SPEED_PATH = "datasets/speed"
SPEED_URL = DOWNLOAD_ROOT + "speed-dating-experiment.zip"
def fetch_speed_data(speed_url=SPEED_URL, speed_path=SPEED_PATH):
if not os.path.isdir(speed_path):
os.makedirs(speed_path)
zip_path = os.path.join(speed_path, "speed.zip")
urllib.request.urlretrieve(speed_url, zip_path)
speed_zip = zipfile.ZipFile(zip_path, 'a')
speed_zip.extractall(path=speed_path)
speed_zip.close()
fetch_speed_data()