diff --git a/lib/routes/thepaper/channel.js b/lib/routes/thepaper/channel.js index d330bac32..4993ecac1 100644 --- a/lib/routes/thepaper/channel.js +++ b/lib/routes/thepaper/channel.js @@ -2,7 +2,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { const { id } = ctx.params; - const link = `https://www.thepaper.cn/channel_${id}`; + const link = `https://m.thepaper.cn/channel_${id}`; const items = await utils.ProcessFeed(link, ctx); ctx.state.data = { diff --git a/lib/routes/thepaper/utils.js b/lib/routes/thepaper/utils.js index d77bda700..5b991a389 100644 --- a/lib/routes/thepaper/utils.js +++ b/lib/routes/thepaper/utils.js @@ -1,5 +1,5 @@ const cheerio = require('cheerio'); -const dayjs = require('dayjs'); +const date = require('@/utils/date'); const got = require('@/utils/got'); module.exports = { @@ -7,32 +7,29 @@ module.exports = { const res = await got.get(link); const $ = cheerio.load(res.data); - const list = $('#mainContent .news_li').slice(0, 10).get(); + const list = $('.t_news').slice(0, 10).get(); return await Promise.all( list.map(async (item) => { const $ = cheerio.load(item); - const itemUrlID = $(item).find('.news_tu a').attr('href'); - const itemUrl = `https://www.thepaper.cn/${itemUrlID}`; + const itemUrlID = $(item).find('.news_tit02 a').attr('href'); + const itemUrl = `https://m.thepaper.cn/${itemUrlID}`; const cache = await ctx.cache.get(itemUrl); if (cache) { return Promise.resolve(JSON.parse(cache)); } + const res = await got.get(itemUrl); const content = cheerio.load(res.data); - const serverOffset = new Date().getTimezoneOffset() / 60; - const author = content('.newscontent .news_about p').slice(0, 1).text(); - content('.newscontent .news_about p span').remove(); - const pubDateStr = content('.newscontent .news_about p').slice(1, 2).text().trim(); + + content('.contheight').replaceWith('
'); + const single = { - title: content('.newscontent .news_title').text(), - guid: itemUrl, + title: content('h1.t_newsinfo').text(), link: itemUrl, - description: content('.newscontent .news_txt').html(), - pubDate: dayjs(pubDateStr) - .add(-8 - serverOffset, 'hour') - .toISOString(), - author: author, + description: $(content('.news_part_limit div')[0]).html(), + pubDate: date($(content('.about_news')[1]).text().trim()), + author: $(content('.about_news')[0]).text(), }; return Promise.resolve(single); })