From ad4faac0bb625a4a18587c714fe189cbd934a0d7 Mon Sep 17 00:00:00 2001 From: howel52 <401738000@qq.com> Date: Wed, 19 Jun 2019 11:25:34 +0800 Subject: [PATCH] feat: add new route flyertea (#2431) * feat: add new route flyertea * fix: docs error fix --- docs/travel.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/flyertea/preferential.js | 33 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 lib/routes/flyertea/preferential.js diff --git a/docs/travel.md b/docs/travel.md index 3ea004f9c..0d67b94b4 100644 --- a/docs/travel.md +++ b/docs/travel.md @@ -45,6 +45,12 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 +## 飞客茶馆 + +### 优惠信息 + + + ## 国家地理 ### 分类 diff --git a/lib/router.js b/lib/router.js index c292a4d3b..44b3cc6e1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1421,4 +1421,7 @@ router.get('/sixthtone/news', require('./routes/sixthtone/news')); // AI研习社 router.get('/aiyanxishe/:id/:sort?', require('./routes/aiyanxishe/home')); +// 飞客茶馆优惠信息 +router.get('/flyertea/preferential', require('./routes/flyertea/preferential')); + module.exports = router; diff --git a/lib/routes/flyertea/preferential.js b/lib/routes/flyertea/preferential.js new file mode 100644 index 000000000..b83aaa92e --- /dev/null +++ b/lib/routes/flyertea/preferential.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +const gbk2utf8 = (s) => iconv.decode(s, 'gbk'); +const host = 'https://www.flyertea.com'; +const target = `${host}/forum.php?mod=forumdisplay&sum=all&fid=all&catid=322`; + +module.exports = async (ctx) => { + const response = await got.get(target, { + responseType: 'buffer', + }); + + const $ = cheerio.load(gbk2utf8(response.data)); + const items = $('.comiis_wzli'); + ctx.state.data = { + title: '飞客茶馆优惠', + link: 'https://www.flyertea.com/', + description: '飞客茶馆优惠', + item: + items && + items + .map((index, item) => { + item = $(item); + return { + title: item.find('.wzbt').text(), + description: item.find('.wznr > div:first-child').text(), + link: `${host}/${item.find('.wzbt a').attr('href')}`, + }; + }) + .get(), + }; +};