總網頁瀏覽量

【 Python學習 】網路連線程式、公開資料串接

 臺北市垃圾車點位路線資訊

資料來源:臺北市資料大平台https://data.taipei/api/v1/dataset/a6e90031-7ec4-4089-afb5-361a4efe7202?scope=resourceAquire

import urllib.request as request
import json
x = "https://data.taipei/api/v1/dataset/a6e90031-7ec4-4089-afb5-361a4efe7202?scope=resourceAquire"
with request.urlopen(x) as response:
data = json.load(response)
print(data)

taipei_list = data["result"]["results"]
print(len(taipei_list))
with open("taipei_garbage.txt", "w", encoding= "utf-8") as file:
for clist in taipei_list:
place = clist.get("里別")
location = clist.get("地點")
arrive_time = clist.get("抵達時間")
leave_time = clist.get("離開時間")
print("------------------------")
output_data = (f" {"里別"}:{place}\n {"地點"}:{location}\n {"抵達時間"}:{arrive_time}\n {"離開時間"}:{leave_time}\n"
f"------------------------")
print(output_data)
file.write(output_data + "\n")

里別:力行里
地點:臺北市中山區建國北路169號前
抵達時間:1630
離開時間:1638
------------------------
里別:力行里
地點:臺北市中山區南京東路3176號前(遼寧街口)
抵達時間:1640
離開時間:1649
------------------------
里別:力行里
地點:臺北市中山區南京東路3214號前
抵達時間:1650
離開時間:1658

(下略)

沒有留言:

張貼留言

2026必勝客超值優惠代碼組合,享受美食就看這邊

94103四小福雙拼系列$199 13吋大比薩,雙拼-四小福+照燒雞 或 四小福+熱帶鳳梨海鮮總匯1個。 平日外帶限定-94199超值單點大比薩$199 13吋大比薩1個,7種超值口味-蒜香起司燻雞培根、義式培根黃金薯等任選。 平日外帶限定-94299人氣單點大比薩$299 13...