diff --git a/docs/new-media.md b/docs/new-media.md index 5c58049d5..1f9c15473 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1875,6 +1875,11 @@ column 为 third 时可选的 category: +## 网易号(通用) + +优先使用方法一,若是网易号搜索页面搜不到的小众网易号(文章页面不含`data-wemediaid`)则可使用此法。 + + ## 网易新闻 ### 排行榜 diff --git a/lib/router.js b/lib/router.js index bb5c2e861..f8cbea130 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/netease/dy2.js b/lib/routes/netease/dy2.js new file mode 100644 index 000000000..fe81eb76d --- /dev/null +++ b/lib/routes/netease/dy2.js @@ -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, + }; +};