python鎬庝箞鏍规嵁url涓嬭浇鍥剧墖
浣犲彲浠ヤ娇鐢≒ython涓殑requests搴撴潵涓嬭浇鍥剧墖銆備互涓嬫槸涓€涓畝鍗曠殑绀轰緥浠g爜锛?/p>
import requests
def download_image(url, file_path):
response = requests.get(url)
if response.status_code == 200:
with open(file_path, 'wb') as file:
file.write(response.content)
print(f"Image downloaded successfully to {file_path}")
else:
print("Failed to download image")
# 鐢ㄦ硶绀轰緥
url = "https://example.com/image.jpg"
file_path = "image.jpg"
download_image(url, file_path)
鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑瀹氫箟浜嗕竴涓?code>download_image鍑芥暟鏉ヤ笅杞藉浘鐗囥€備綘鍙渶瑕佷紶鍏ュ浘鐗囩殑URL鍜屼繚瀛樼殑鏂囦欢璺緞浣滀负鍙傛暟璋冪敤璇ュ嚱鏁板嵆鍙笅杞藉浘鐗囥€?/p>