
使用 App Inventor 爬取 i郵箱據點 (更新版)
之前我有寫過一篇「使用 App Inventor 爬取 i郵箱據點」的教學文章,在四天前 (七月一號) 使用 App 時跳出了錯誤訊息,到了開放資料網站看才發現,之前讀取時所選用的 JSON 格式資料的那一列不見了!雖然現在它又回來了,但是上面多了一行「以下連結為本平臺協助提供多元格式參考資料 (轉檔時間:2022-07-05 15:26:41), 非即時資料, 完整資料請以機關 原始連結 為主。」,而且我也早已把 App 更新了,所以這一次就來分享,如何修改程式方塊來讀取新的格式的資料。

這一篇文章不會有很詳細的教學,因為只是簡單修改一下而已,所以一些程式的用法請參考上一篇內容,那麼請跟著以下的教學開始實作:
1. 打開 App Inventor 網站,開啟之前的專案。
首先要修改的是,網路元件的網址,這個方塊在「下載按鈕被點選」的方塊裡,修改網址如下:
https://www.post.gov.tw/post/internet/Templates/getOpenDataFile.jsp?vkey=1A689FD9-3BB3-46C9-8D2E-1740616A811F

這個網址在 i郵箱資料開放網站可以找到,這個資料的檔案格式為 CSV。

把這個資料下載下來,用記事本或 Excel 打開,可以看到這個資料很單純,在 App Inventor 用「CSV 表格轉清單」的方塊,轉過去後就是二維清單,跟原本讀取時沒什麼太大的差別,只是無法使用「在鍵值… 找關鍵字…」的方塊,但只要改用「選擇清單… 索引值…」的方塊即可。

接著我們來修改,讀取到資料後要解碼的方塊,它在「當網路元件取得文字」裡面,修改如下:

原本讀取的 JSON 格式的資料沒有包含標題,但 CSV 格式的有,所以我們將第一筆資料刪掉。
再來我們要將「在鍵值… 找關鍵字…」的方塊全部改成「選擇清單… 索引值…」的方塊。
例如:在「網路元件取得文字」方塊的裡面就有一個找關鍵字為「名稱」的方塊

然後將這個方塊改成如下:

Q:我要怎麼知道索引值要改多少?
Ans:很簡單!以上述為例,要找的是「名稱」的內容,只要將剛剛下載的 CSV 檔案打開,看「名稱」在第幾欄,就填對應的數字。

所有找關鍵字的欄位都這樣修改即可 (包含副程式裡的也要)

請將所有關鍵字方塊都修改!
到這裡,這個 App 就全部修改完畢可以執行了!

完整程式方塊

專案範例 aia 檔案下載
專案範例操作影片
如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝
可以多點幾次喔~~
第一次點讚需使用 Google 或 Facebook 帳號註冊

