註冊 登錄
Android 台灣中文網 返回首頁

jianrupan的個人空間 https://apk.tw/?1180935 [收藏] [複製] [分享] [RSS]

日誌

Python 網路連線、公開資料串接 學習

已有 466 次閱讀2021-11-3 15:55 |個人分類:軟體應用| Python, 網路, 連線, 公開, 資料


# 下載特定網址資料

# 下載特定網址資料

src = "https://www.ntu.edu.tw/" à 台大首頁

with request.urlopen(src) as response:

    data = response.read().decode("utf-8")  # 取得網站原始碼(HTML, CSS, JS)

print("讀取 "+src+" 網頁原始碼: ")

print(data)

print()

 

# 串接, 擷取公開資料

# 下載模組

import json

# 台北市政府公開資料 -> 臺北市內湖科技園區廠商名錄 https://data.taipei/#/dataset/detail?id=15c3e1ae-899b-466c-a536-208497e3a369

src = "https://data.taipei/api/v1/dataset/296acfa2-5d93-4706-ad58-e83cc951863c?scope=resourceAquire"

with request.urlopen(src) as response:

   data = json.load(response)  # 利用 json 模組處理 json 資料格式

print("讀取 "+src+" 網頁原始碼: ")

print(data)

 

# 將公司名稱列表

clist = data["result"]["results"]

print("公司名稱: ")

for company in clist:

    print(company["公司名稱"])

# 公司名稱列表 寫入檔案

with open("公司名稱列表.txt", "w", encoding="utf-8") as wFile:

    for company in clist:

        wFile.write(company["公司名稱"]+" ")

 


路過

雞蛋

鮮花

握手

雷人

評論 (0 個評論)

facelist

您需要登錄後才可以評論 登錄 | 註冊