正在載入內容...
香港自殺報道資料庫
API v2 使用與格式說明文檔
https://hkspd.siuyeong.com/guide-api_v2
```
import requests
import json
def get_latest_record():
# API 基礎網址
url = "https://hkspd.siuyeong.com/api_v2"
# 設定查詢參數 (Query Parameters)
params = {
"limit": 1, # 只取一筆記錄
"order": "desc" # 以降序排序 (最新到最舊)
}
try:
# 發送 GET 請求
print("正在呼叫 API 獲取最新記錄...")
response = requests.get(url, params=params)
# 檢查 HTTP 狀態碼是否為 200 (成功)
response.raise_for_status()
# 將回傳結果解析為 JSON 格式
data = response.json()
# 從 JSON 中提取 records 陣列
records = data.get("records", [])
if records:
latest_record = records[0]
print("\n✅ 成功獲取最新一筆記錄!\n")
# 列印出部分關鍵欄位 (您可以根據需求增刪)
print(f"個案編號 (caseID): {latest_record.get('caseID')}")
print(f"發現日期 (caseDate): {latest_record.get('caseDate')} {latest_record.get('caseTime')}")
print(f"區域/分區: {latest_record.get('Area')} {latest_record.get('District')} {latest_record.get('subDistrict')}")
print(f"性別/年齡: {latest_record.get('Gender')} / {latest_record.get('Age')}歲")
print(f"綜合狀態: {latest_record.get('State')}")
print(f"新聞網址: {latest_record.get('newsURL')}")
print("\n--- 完整 JSON 數據 ---")
# 格式化輸出完整的 JSON 以方便閱讀
print(json.dumps(latest_record, ensure_ascii=False, indent=2))
else:
print("目前資料庫中沒有任何記錄。")
except requests.exceptions.RequestException as e:
print(f"❌ API 請求失敗發生錯誤: {e}")
if __name__ == "__main__":
get_latest_record()
```
---
```
正在呼叫 API 獲取最新記錄...
✅ 成功獲取最新一筆記錄!
個案編號 (caseID): 2026063004
發現日期 (caseDate): 2026-06-30 10:00
區域/分區: 九龍 黃大仙區 慈雲山
性別/年齡: 男 / 37歲
綜合狀態: 身亡
新聞網址: https://siuyeo.ng/hkspd202606301000
--- 完整 JSON 數據 ---
{
"caseID": "2026063004",
"newsDate": "2026-06-30",
"newsTime": "11:50",
"newsHelp": "有",
"newsURL": "https://siuyeo.ng/hkspd202606301000",
"caseDate": "2026-06-30",
"caseTime": "10:00",
"Area": "九龍",
"District": "黃大仙區",
"subDistrict": "慈雲山",
"Unit": "慈樂邨",
"subUnit": "樂合樓",
"Latitude": "22.3469484383018",
"Longitude": "114.199998996775",
"House": "公共屋邨",
"firstName": "呂",
"Gender": "男",
"Age": "37",
"Hospitalized": "沒有",
"State": "身亡",
"suicideNote": "沒有",
"mental_illness": "沒有",
"emotional_illness": "沒有",
"missingRecord": "有",
"reason1": "財政",
"type1": "跳落"
}
```