iT邦幫忙

2022 iThome 鐵人賽

DAY 11
0
DevOps

其實沒有那麼難 — Docker系列 第 11

D11 - 團隊觀戰區爬蟲 v2

  • 分享至 

  • xImage
  •  

回顧一下我們上一次做的玩具 D8 - 團隊觀戰區爬蟲
我們透過爬取鐵人賽的網頁,來獲取整個團隊的參賽狀況,

身為後端,那我們就來把它做成 API 吧!


微調爬蟲程式

上次我們已經可以用爬蟲拿到資訊了,但我們只是把它們都印在 Terminal 及輸出到檔案中,
我們稍微再擴充一點欄位,之後再加入一個 Express router,把它架成 Server,提供 API 給前端使用,

Endpoint: {base_url}/team/:teamId/members

在這支 API 中,我們傳入 team id,像是我們團隊的 ID 是 249,我的程式接著去爬取所有成員再回傳 json。

另外,D5 - Hello World ft. Express 已經講解過 Express 的使用方式跟 Dockerfile 定義,需要的讀者可以回顧一下。


Deploy

如果讀者有自己的 Server,可以把這段程式佈署到 Server 上,

另外,如果 Server 是開在雲端平台上,例如 AWS、GCP、Azure、Linode 等等,
記得要到雲端平台的後台,把這台 Server 的 Port 3000 對外開放,
雖然這是一個很小的問題,但偶爾會不小心忽略,而使 API 無法讓前端使用。

# 建置 image
$ sudo docker build . -t ithelp-team-crawler-server

# 啟動 Server
$ sudo docker run  --detach  --publish=3000:3000  ithelp-team-crawler-server

Response

這次的爬蟲程式碼可以在 這裡 找到,

同時附上我們團隊今晚的發文資訊 衝個字數

{
	"data": [
		{
			"teamId": 249,
			"seriesTitle": "JavaScript 之路,往前邁進吧!",
			"authorName": "Vic",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20151114/ironman/5425",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/174235?s=ithelp",
			"latestPostTitle": "JS之路 Day11 - Callback Funtion(回呼函式)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298979",
			"latestPostedAt": "2022-09-26T12:10:55.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "想轉職的鯊魚從零基礎開始學習JavaScript",
			"authorName": "nikihypocrite",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20143214/ironman/5190",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/165553?s=ithelp",
			"latestPostTitle": "想轉職的鯊魚從零基礎開始學習JavaScript Day-10 ECMAScript Language-概述(一)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298506",
			"latestPostedAt": "2022-09-25T15:00:49.000Z",
			"postLength": 10,
			"participationDays": 10
		},
		{
			"teamId": 249,
			"seriesTitle": "[學習筆記] 邊學邊寫 JavaScript 30天",
			"authorName": "LeeFang",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20145552/ironman/5213",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/168057?s=ithelp",
			"latestPostTitle": "[學習筆記] 邊學邊寫 JavaScript 30天 (11):課後題目練習",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10299046",
			"latestPostedAt": "2022-09-26T13:13:07.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "從 Google Material Design Components 來了解與實作 Android 的 UI/UX 元件設計",
			"authorName": "vosscg0822",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20151680/ironman/5440",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/174820?s=ithelp",
			"latestPostTitle": "Day 11 - Checkboxes (Design & Implementation)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298626",
			"latestPostedAt": "2022-09-25T17:11:12.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "前端蛇行撞牆記",
			"authorName": "jadddxx",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152424/ironman/5659",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175620?s=ithelp",
			"latestPostTitle": "Day11 前端蛇行撞牆記 - 屬性描述器",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298757",
			"latestPostedAt": "2022-09-26T03:09:42.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "30天的 iOS 修仙道路 站穩腳步基礎篇",
			"authorName": "地方號稱165的大叔",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152431/ironman/5662",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175627?s=ithelp",
			"latestPostTitle": "30天的 iOS 修仙道路 (11)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298890",
			"latestPostedAt": "2022-09-26T07:40:35.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "當軟體PM的動畫師:人生相談室",
			"authorName": "jirungyang",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152475/ironman/5680",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175674?s=ithelp",
			"latestPostTitle": "[英文] 英文自學小心得 - ANKI aka 永遠背不完ㄉ單字",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298644",
			"latestPostedAt": "2022-09-25T20:19:02.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "從Create到React—用來實作使用者介面的JavaScript函式庫",
			"authorName": "DannyChen",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20125095/ironman/5682",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/146159?s=ithelp",
			"latestPostTitle": "React—jsx基本介紹、snippet、各種css style解決方案",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10299028",
			"latestPostedAt": "2022-09-26T12:44:00.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "其實沒有那麼難 — Docker",
			"authorName": "Louis",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20120541/ironman/5683",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/141351?s=ithelp",
			"latestPostTitle": "D10 - Database by Docker",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298321",
			"latestPostedAt": "2022-09-25T11:24:23.000Z",
			"postLength": 10,
			"participationDays": 10
		},
		{
			"teamId": 249,
			"seriesTitle": "新手向Android&Kotlin學習紀錄30天",
			"authorName": "Yimin",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152479/ironman/5685",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175678?s=ithelp",
			"latestPostTitle": "第11天 ConstraintLayout 詳細介紹(四) : Flow、ImageFilterView、ImageFliterButton",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298806",
			"latestPostedAt": "2022-09-26T04:41:22.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "這才是真正的共同工作空間",
			"authorName": "Howard",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20107159/ironman/5711",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/126028?s=ithelp",
			"latestPostTitle": "不著痕跡的製造機會",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298603",
			"latestPostedAt": "2022-09-25T16:16:33.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "PixiJS青銅玩家",
			"authorName": "NoZ",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152526/ironman/5741",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175666?s=ithelp",
			"latestPostTitle": "【LV. 11】PixiJS青銅玩家:setUp( )(3)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298843",
			"latestPostedAt": "2022-09-26T06:03:29.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "如何成為IOS初級工程師",
			"authorName": "iRogerz",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20152659/ironman/5847",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/175576?s=ithelp",
			"latestPostTitle": "Day-11  使用UIKit框架建立iOS App專案(without storyboard)",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298398",
			"latestPostedAt": "2022-09-26T04:29:12.000Z",
			"postLength": 11,
			"participationDays": 11
		},
		{
			"teamId": 249,
			"seriesTitle": "Kotlin on the way",
			"authorName": "Kenny",
			"ironmanPageUrl": "https://ithelp.ithome.com.tw/users/20141766/ironman/5870",
			"originalAuthorImageUrl": "https://member.ithome.com.tw/avatars/164016?s=ithelp",
			"latestPostTitle": "OO 能吃嗎? 繼承 inheritance",
			"latestPostUrl": "https://ithelp.ithome.com.tw/articles/10298878",
			"latestPostedAt": "2022-09-26T07:12:08.000Z",
			"postLength": 11,
			"participationDays": 11
		}
	]
}

上一篇
D10 - Database by Docker
下一篇
D12 - Image Size
系列文
其實沒有那麼難 — Docker30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言