feat: add 网易号(通用) (#6748)
This commit is contained in:
parent
b969d1298a
commit
ec7568146b
|
|
@ -1875,6 +1875,11 @@ column 为 third 时可选的 category:
|
|||
|
||||
</Route>
|
||||
|
||||
## 网易号(通用)
|
||||
|
||||
优先使用方法一,若是网易号搜索页面搜不到的小众网易号(文章页面不含`data-wemediaid`)则可使用此法。
|
||||
<Route author="mjysci" example="netease/dy2/T1555591616739" path="/netease/dy2/:id" :paramsDesc="['id,该网易号主页网址最后一项html的文件名']"/>
|
||||
|
||||
## 网易新闻
|
||||
|
||||
### 排行榜
|
||||
|
|
|
|||
|
|
@ -3060,6 +3060,7 @@ router.get('/netease/news/data', require('./routes/netease/news/data'));
|
|||
|
||||
// 网易 - 网易号
|
||||
router.get('/netease/dy/:id', require('./routes/netease/dy'));
|
||||
router.get('/netease/dy2/:id', require('./routes/netease/dy2'));
|
||||
|
||||
// 网易大神
|
||||
router.get('/netease/ds/:id', require('./routes/netease/ds'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const url = `https://www.163.com/dy/media/${id}.html`;
|
||||
|
||||
const response = await got.get(url, { responseType: 'buffer' });
|
||||
|
||||
const data = iconv.decode(response.data, 'gbk');
|
||||
const $ = cheerio.load(data, { decodeEntities: false });
|
||||
|
||||
const list = $('.media_articles ul li')
|
||||
.slice(0, 3)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('h2.media_article_title a');
|
||||
let pubDate = item.find('.media_article_date').text();
|
||||
pubDate = new Date(pubDate).toUTCString();
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: pubDate,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
let link;
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
let content;
|
||||
if (item.link.startsWith('https://www.163.com')) {
|
||||
const itemData = await ctx.cache.tryGet(item.link, async () =>
|
||||
iconv.decode(
|
||||
(
|
||||
await got.get(item.link, {
|
||||
responseType: 'buffer',
|
||||
})
|
||||
).data,
|
||||
'gbk'
|
||||
)
|
||||
);
|
||||
content = cheerio.load(itemData, { decodeEntities: false });
|
||||
} else {
|
||||
const response = await got.get(item.link);
|
||||
content = cheerio.load(response.data, { decodeEntities: false });
|
||||
}
|
||||
|
||||
const eDescription = content('.post_body').html();
|
||||
|
||||
const single = {
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
description: eDescription,
|
||||
pubDate: item.pubDate,
|
||||
};
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('.media_info h1').text(),
|
||||
link,
|
||||
description: '',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue