From 3e393ccce8f8f48267b70a43340c3d908a50f9fd Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Sun, 15 Jan 2023 22:36:13 +0800 Subject: [PATCH] fix(route): thepaper list error and change to api.thepaper.cn (#11623) * fix thepaper list error and change to api.thepaper.cn * fix channel id in thepaper docs * fix channel id in thepaper docs * remove the trailing space in --- docs/traditional-media.md | 3 +-- lib/v2/thepaper/channel.js | 16 +++++++++++----- lib/v2/thepaper/list.js | 16 +++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 79c8b7052f..9bee2294d1 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1694,7 +1694,6 @@ category 对应的关键词有 | 频道 ID | 频道名 | | ------ | --- | -| 25949 | 要闻 | | 26916 | 视频 | | 108856 | 战疫 | | 25950 | 时事 | @@ -1705,9 +1704,9 @@ category 对应的关键词有 | 119489 | 智库 | | 25953 | 生活 | | 26161 | 问吧 | +| 122908 | 国际 | | -21 | 体育 | | -24 | 评论 | -| -23 | 国际 | diff --git a/lib/v2/thepaper/channel.js b/lib/v2/thepaper/channel.js index 0f1c4dc8c7..0772113bdc 100644 --- a/lib/v2/thepaper/channel.js +++ b/lib/v2/thepaper/channel.js @@ -5,16 +5,22 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { const { id } = ctx.params; const channel_url = `https://m.thepaper.cn/channel/${id}`; - const response = await got(channel_url); - const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html()); - const list = data.props.pageProps.data.list; + const channel_url_resp = await got(channel_url); + const channel_url_data = JSON.parse(cheerio.load(channel_url_resp.data)('#__NEXT_DATA__').html()); + + const resp = await got.post('https://api.thepaper.cn/contentapi/nodeCont/getByChannelId', { + json: { + channelId: id, + }, + }); + const list = resp.data.data.list; const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx))); ctx.state.data = { - title: `澎湃新闻频道 - ${utils.ChannelIdToName(id, data)}`, + title: `澎湃新闻频道 - ${utils.ChannelIdToName(id, channel_url_data)}`, link: channel_url, item: items, itunes_author: '澎湃新闻', - image: utils.ExtractLogo(response), + image: utils.ExtractLogo(channel_url_resp), }; }; diff --git a/lib/v2/thepaper/list.js b/lib/v2/thepaper/list.js index 0712f9dc35..2198531dd5 100644 --- a/lib/v2/thepaper/list.js +++ b/lib/v2/thepaper/list.js @@ -5,17 +5,23 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { const { id } = ctx.params; const list_url = `https://m.thepaper.cn/list/${id}`; - const response = await got(list_url); - const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html()); - const pagePropsData = data.props.pageProps.data; + const list_url_resp = await got(list_url); + const list_url_data = JSON.parse(cheerio.load(list_url_resp.data)('#__NEXT_DATA__').html()); + + const resp = await got.post('https://api.thepaper.cn/contentapi/nodeCont/getByNodeIdPortal', { + json: { + nodeId: id, + }, + }); + const pagePropsData = resp.data.data; const list = pagePropsData.list; const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx))); ctx.state.data = { - title: `澎湃新闻栏目 - ${utils.ListIdToName(id, data)}`, + title: `澎湃新闻栏目 - ${utils.ListIdToName(id, list_url_data)}`, link: list_url, item: items, itunes_author: '澎湃新闻', - image: pagePropsData.nodeInfo?.pic ?? utils.ExtractLogo(response), + image: pagePropsData.nodeInfo?.pic ?? utils.ExtractLogo(list_url_resp), }; };