From ba06c26875e8fdaf3b557adcf3f46399f5d8d696 Mon Sep 17 00:00:00 2001 From: mifang Date: Thu, 16 Apr 2020 19:47:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20bbs=E8=B7=AF=E7=94=B1=20eTOLAND?= =?UTF-8?q?=20(#4465)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bbs.md | 6 +++++ lib/router.js | 3 +++ lib/routes/etoland/board.js | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/etoland/board.js diff --git a/docs/bbs.md b/docs/bbs.md index cb7f12981..1ed898fbb 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -82,6 +82,12 @@ pageClass: routes +## eTOLAND + +### 主题贴 + + + ## LearnKu ### 社区 diff --git a/lib/router.js b/lib/router.js index 0fb5966d5..a86a28a35 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2536,4 +2536,7 @@ router.get('/iyouport/article', require('./routes/iyouport')); // girlimg router.get('/girlimg/album/:tag?/:mode?', require('./routes/girlimg/album')); +// etoland +router.get('/etoland/:bo_table', require('./routes/etoland/board')); + module.exports = router; diff --git a/lib/routes/etoland/board.js b/lib/routes/etoland/board.js new file mode 100644 index 000000000..e9d522427 --- /dev/null +++ b/lib/routes/etoland/board.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const date = require('@/utils/date'); + +module.exports = async (ctx) => { + const { bo_table } = ctx.params; + + const response = await got({ + method: 'get', + url: `http://www.etoland.co.kr/bbs/board.php?bo_table=${bo_table}`, + responseType: 'buffer', + }); + + const data = iconv.decode(response.data, 'euc-kr'); + + const $ = cheerio.load(data); + const list = $('form[name="fboardlist"]>table tr[align="center"]').filter((index, item) => { + item = $(item); + return item.find('td').first().find('span.mw_basic_list_num').length > 0; + }); + + ctx.state.data = { + title: 'eTOLAND', + link: 'http://www.etoland.co.kr', + language: 'ko-KR', + description: 'eTOLAND', + item: + list && + list + .map((index, item) => { + item = $(item); + const title = item.find('td.mw_basic_list_subject a:nth-child(3) span').text(); + const description = `点赞数:${item.find('td.mw_basic_list_good').text()}
浏览数:${item.find('td.mw_basic_list_hit').text()}`; + const link = item.find('td.mw_basic_list_subject a:nth-child(3)').attr('href'); + + return { + title: title, + description: description, + link: link, + pubDate: date(item.find('td.mw_basic_list_datetime').text()), + }; + }) + .get(), + }; +};