import requests
# 圖片的URL地址
url = 'https://book.pep.com.cn/1212001402143/files/mobile/1.jpg?240301113921'
# 發送HTTP GET請求
response = requests.get(url)
# 檢查請求是否成功
if response.status_code == 200:
? ? # 打開一個文件用于寫入
? ? with open('downloaded_image.jpg', 'wb') as file:
? ? ? ? # 將圖片內容寫入文件
? ? ? ? file.write(response.content)
? ? print('圖片已成功下載并保存到本地。')
else:
? ? print('圖片下載失敗,狀態碼:', response.status_code)
------------------------以上為示例代碼---------------------------------
補充:需要有requests的庫,沒有的話,先執行pip install requests