feat: add 百度知道-日报精选 (#4883)
This commit is contained in:
parent
561e8ba4a6
commit
1c6a4acbb8
|
|
@ -343,6 +343,12 @@ Supported sub-sites:
|
|||
|
||||
<Route author="hillerliao" example="/8btc/news/flash" path="/8btc/news/flash"/>
|
||||
|
||||
## 百度知道日报
|
||||
|
||||
### 精选
|
||||
|
||||
<Route author="1813927768" example="/baidu/daily" path="/baidu/daily"/>
|
||||
|
||||
## 白鲸出海
|
||||
|
||||
### 首页最新帖子
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue