fork download
  1. import requests
  2.  
  3. def download_mp3(url, save_path):
  4. try:
  5. # ส่ง HTTP request ไปยัง URL
  6. response = requests.get(url)
  7.  
  8. # เช็คสถานะการตอบกลับ
  9. if response.status_code == 200:
  10. # เปิดไฟล์เพื่อเขียนข้อมูลลงไป
  11. with open(save_path, 'wb') as f:
  12. f.write(response.content)
  13. print(f"ดาวน์โหลดเสร็จสมบูรณ์: {save_path}")
  14. else:
  15. print(f"ไม่สามารถดาวน์โหลดไฟล์ได้ (สถานะ {response.status_code})")
  16.  
  17. except Exception as e:
  18. print(f"เกิดข้อผิดพลาด: {e}")
  19.  
  20.  
Success #stdin #stdout 0.03s 25932KB
stdin
Standard input is empty
stdout
import requests

def download_mp3(url, save_path):
    try:
        # ส่ง HTTP request ไปยัง URL
        response = requests.get(url)
        
        # เช็คสถานะการตอบกลับ
        if response.status_code == 200:
            # เปิดไฟล์เพื่อเขียนข้อมูลลงไป
            with open(save_path, 'wb') as f:
                f.write(response.content)
            print(f"ดาวน์โหลดเสร็จสมบูรณ์: {save_path}")
        else:
            print(f"ไม่สามารถดาวน์โหลดไฟล์ได้ (สถานะ {response.status_code})")
    
    except Exception as e:
        print(f"เกิดข้อผิดพลาด: {e}")