[Nodejs] 網絡爬蟲 Dcard 圖片下載實例

Peter Chang
2 min readFeb 22, 2017

--

現實生活上,實在有太多的網絡公司通過網絡爬蟲為用戶提供網絡服務,組合成各式各樣的商業模式。這個 Project 是以 Cheerio 為基礎,和台灣最受大學生歡迎的 Dcard 平台為例,通過 Node.js 完成圖片爬蟲實例。

要理解此 repository 需要以下三方面的知識:

  1. cheerio 爬蟲工具
  2. async/await
  3. babel (es6)

Install

$ git clone https://github.com/wahengchang/node-dcard-scraper
$ npm install

Run

如果想修改其他想爬蟲的頁面, 只要在 dcardModule.js 中更改 subUrl 即可。

$ npm start

結果

預設的搜尋頁面是 f/vehicle, 下面是其一個一個頁面的顯示畫面. 當程式跑完該圖片也應該會下載到 local 端.

上圖在該主題的圖片成功地下載在download 資料夾.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Peter Chang
Peter Chang

Responses (1)

Write a response