Python 將網頁內容儲存至檔案中

在 python 中可以使用內建的 urllib 函式庫來處理 URL 請求,也有內建的方法可以直接將檔案儲存到本機中:
    
import urllib.request

url = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png"
local_path = "image1.png"

try:
    urllib.request.urlretrieve(url, local_path)
    print("檔案下載成功")
except Exception as e:
    print(f"下載失敗:{e}")

    

文章撰寫中...請稍後...

留言