基本的http文件在python中下載並保存到磁盤?

| | | | |

我是 Python 新手,我一直在瀏覽這個網站上的問答,以回答我的問題。但是,我是初學者,我發現有些解決方案很難理解。我需要一個非常基本的解決方案。

有人可以解釋一下“通過http下載文件”和“保存”的簡單解決方案它到磁盤,在 Windows 中”,對我來說?

我也不確定如何使用 shutil 和 os 模塊。

我要下載的文件小於 500 MB並且是一個 .gz 存檔文件。如果有人可以解釋如何提取存檔並利用其中的文件,那就太好了!

這裡是部分解決方案,我結合各種答案編寫的:

import requests import os import shutil global dump def download_file(): global dump url = "http://randomsite.com/file.gz" file = requests.get(url, stream =True) dump = file.raw def save_file(): global dump location = os.path.abspath("D:folderfile.gz") with open("file.gz", "wb") as location: shutil.copyfileobj (dump, location) del dump 

誰能指出錯誤(初級)並解釋一下有更簡單的方法嗎?

謝謝!

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method