fix: 网易新闻文章内视频无效 (#6091)
This commit is contained in:
parent
2c3a35f3bc
commit
c6f6ea4194
|
|
@ -43,7 +43,7 @@ const config = {
|
|||
title: '房产',
|
||||
},
|
||||
game: {
|
||||
link: '/special/0001386F/rank_game.html',
|
||||
link: '/special/0001386F/game_rank.html',
|
||||
title: '游戏',
|
||||
},
|
||||
travel: {
|
||||
|
|
@ -101,10 +101,10 @@ module.exports = async (ctx) => {
|
|||
const list = $('div.tabContents')
|
||||
.eq(time[ctx.params.time].index + (ctx.params.category === 'whole' ? (ctx.params.type === 'click' ? -1 : 2) : ctx.params.type === 'click' ? 0 : 2))
|
||||
.find('table tbody tr td a')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
})
|
||||
|
|
@ -115,42 +115,22 @@ module.exports = async (ctx) => {
|
|||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
try {
|
||||
let res;
|
||||
let content;
|
||||
if (item.link.startsWith('https://ent.163.com')) {
|
||||
res = await got({ method: 'get', url: item.link, responseType: 'buffer' });
|
||||
content = cheerio.load(iconv.decode(res.data, 'gbk'));
|
||||
} else {
|
||||
res = await got.get(item.link);
|
||||
content = cheerio.load(res.data);
|
||||
}
|
||||
const category = item.link.split('.163.com')[0].split('//').pop().split('.').pop();
|
||||
const link = `https://3g.163.com/${category}/article/${item.link.split('/').pop()}`;
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
if (content('#ne_wrap').attr('data-publishtime')) {
|
||||
// To get pubDate from most pages.
|
||||
content('.bot_word').remove();
|
||||
content('video').each(function () {
|
||||
content(this).attr('src', content(this).attr('data-src'));
|
||||
});
|
||||
|
||||
item.pubDate = new Date(content('#ne_wrap').attr('data-publishtime') + ' GMT+8').toUTCString();
|
||||
} else if (content('div.headline span').text()) {
|
||||
// To get pubDate from special pages in Money.
|
||||
// eg. https://money.163.com/20/0513/14/FCH1G10000259E8J.html
|
||||
|
||||
item.pubDate = new Date(content('div.headline span').text() + ' GMT+8').toUTCString();
|
||||
} else if (content('meta[property="article:published_time"]').attr('content')) {
|
||||
// To get pubDate from pages with image collections.
|
||||
// eg. http://lady.163.com/photoview/00A70026/115695.html
|
||||
|
||||
item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString();
|
||||
}
|
||||
|
||||
if (content('#endText').html()) {
|
||||
// To get description from most pages.
|
||||
|
||||
item.description = content('#endText').html();
|
||||
} else if (content('div.biz_plus_content').html()) {
|
||||
// To get description from special pages in Money.
|
||||
// eg. https://money.163.com/20/0513/14/FCH1G10000259E8J.html
|
||||
|
||||
item.description = content('div.biz_plus_content').html();
|
||||
}
|
||||
item.title = content('meta[property="og:title"]').attr('content').replace('_手机网易网', '');
|
||||
item.pubDate = content('meta[property="og:release_date"]').attr('content');
|
||||
item.description = content('.content').html();
|
||||
|
||||
return item;
|
||||
} catch (err) {
|
||||
|
|
@ -162,7 +142,7 @@ module.exports = async (ctx) => {
|
|||
|
||||
ctx.state.data = {
|
||||
title: `网易新闻${time[ctx.params.time].title}${ctx.params.type === 'click' ? '点击' : '跟帖'}榜 - ${cfg.title}`,
|
||||
link: rootUrl,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue