From b0fca02e4e6b56d1df09571cd1ba0ae54ac4e4a2 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 8 May 2020 11:29:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=B9=BF=E5=91=8A=E9=97=A8?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=B8=8E=E8=AF=9D=E9=A2=98=E5=88=86=E7=B1=BB?= =?UTF-8?q?=20(#4690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 +++++++ lib/router.js | 3 ++ lib/routes/adquan/index.js | 73 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 lib/routes/adquan/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 67deebba0..bc401a6e4 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -501,6 +501,18 @@ Supported sub-sites: +## 广告门 + +### 板块 + + + +| 行业观察 | 案例库 | +| -------- | -------- | +| info | creative | + + + ## 果壳网 ### 科学人 diff --git a/lib/router.js b/lib/router.js index 02ffad55d..92ddfeea5 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2644,6 +2644,9 @@ router.get('/slu/csggxy/:id', require('./routes/universities/slu/csggxy')); router.get('/ruby-china/topics/:type?', require('./routes/ruby-china/topics')); router.get('/ruby-china/jobs', require('./routes/ruby-china/jobs')); +// 广告网 +router.get('/adquan/:type?', require('./routes/adquan/index')); + // 齐鲁晚报 router.get('/qlwb/news', require('./routes/qlwb/news')); router.get('/qlwb/city/:city', require('./routes/qlwb/city')); diff --git a/lib/routes/adquan/index.js b/lib/routes/adquan/index.js new file mode 100644 index 000000000..c359586cf --- /dev/null +++ b/lib/routes/adquan/index.js @@ -0,0 +1,73 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + index: { + link: 'https://www.adquan.com/', + title: '首页', + }, + info: { + link: 'https://www.adquan.com/info', + title: '行业观察', + }, + creative: { + link: 'https://creative.adquan.com/', + title: '案例库', + }, +}; + +module.exports = async (ctx) => { + let cfg; + if (ctx.params.type) { + cfg = config[ctx.params.type]; + } else { + cfg = config.index; + } + + const response = await got({ + method: 'get', + url: cfg.link, + }); + const $ = cheerio.load(response.data); + + let where; + switch (cfg.title) { + case '首页': + where = $('div.w_l_inner h2.wrok_l_title a'); + break; + case '行业观察': + where = $('div.article_rel div.rel_write a p').parent(); + break; + case '案例库': + where = $('#showcontent li h2 a'); + break; + } + + const list = where + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: url.resolve(cfg.link, item.attr('href')), + }; + }) + .get(); + + ctx.state.data = { + title: `广告网 - ${cfg.title}`, + link: cfg.link, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ method: 'get', url: item.link }); + const content = cheerio.load(detailResponse.data); + item.pubDate = new Date(content('p.text_time2 span').eq(0).text()).toUTCString(); + item.description = content('div.con_Text').html(); + return item; + }) + ) + ), + }; +};