diff --git a/docs/new-media.md b/docs/new-media.md index 77b9c4925..93f3d174f 100755 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -343,6 +343,12 @@ Supported sub-sites: +## 百度知道日报 + +### 精选 + + + ## 白鲸出海 ### 首页最新帖子 diff --git a/lib/router.js b/lib/router.js index 6835eba9d..ddcb92c86 100644 --- a/lib/router.js +++ b/lib/router.js @@ -975,6 +975,7 @@ router.get('/geekpark/breakingnews', require('./routes/geekpark/breakingnews')); // 百度 router.get('/baidu/doodles', require('./routes/baidu/doodles')); router.get('/baidu/topwords/:boardId?', require('./routes/baidu/topwords')); +router.get('/baidu/daily', require('./routes/baidu/daily')); // 搜狗 router.get('/sogou/doodles', require('./routes/sogou/doodles')); diff --git a/lib/routes/baidu/daily.js b/lib/routes/baidu/daily.js new file mode 100644 index 000000000..79735134b --- /dev/null +++ b/lib/routes/baidu/daily.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const host = `https://zhidao.baidu.com/daily?fr=daohang`; + + const response = await got.get(host, { + responseType: 'buffer', + }); + + response.data = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(response.data); + + const list = $("li[class=' clearfix']").get(); + + const items = list.map((item) => { + item = $(item); + + return { + title: item.find('div.daily-cont-top > h2 > a').text(), + description: item.find('div.daily-cont-top > div > a').text(), + link: `https://zhidao.baidu.com/${item.find('div.daily-cont-top > h2 > a').attr('href')}`, + }; + }); + + const result = await Promise.all( + items.map(async (item) => { + const link = item.link; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got.get(link, { + responseType: 'buffer', + }); + const data = iconv.decode(itemReponse.data, 'gbk'); + const itemElement = cheerio.load(data); + + item.description = itemElement('.detail-wp').html(); + + ctx.cache.set(link, JSON.stringify(item)); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: `知道日报`, + link: host, + description: `每天都知道一点`, + item: result, + }; +};