diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 51e658cf9..6c7675e49 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1709,6 +1709,12 @@ category 对应的关键词有 +## 中国新闻网 + +### 最新 + + + ## 中山网 ### 中山网新闻 diff --git a/lib/v2/chinanews/index.js b/lib/v2/chinanews/index.js new file mode 100644 index 000000000..c8e56821a --- /dev/null +++ b/lib/v2/chinanews/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const cheerio = require('cheerio'); + +const rootUrl = 'https://www.chinanews.com.cn'; + +module.exports = async (ctx) => { + const currentUrl = `${rootUrl}/scroll-news/news1.html`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('a', '.dd_bt') + .map((_, item) => ({ + link: rootUrl + $(item).attr('href'), + title: $(item).text(), + })) + .get() + .slice(0, ctx.query.limit ? (parseInt(ctx.query.limit) > 125 ? 125 : parseInt(ctx.query.limit)) : 50); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + if (content('div.content_desc').length > 0) { + item.description = content('div.content_desc').text(); + item.author = content('a.source').text(); + const info = content('p', '.left').text().trim().slice(5).split(' '); + item.author = info[2].trim(); + item.pubDate = timezone(parseDate(info[0] + info[1], 'YYYY年MM月DD日HH:mm'), +8); + } else if (content('div.t3').length > 0) { + item.description = content('div.t3').text(); + const info = content('div[style="text-align:right;font-size:12px;"]').text().slice(5).split(' '); + item.author = info[2]; + item.pubDate = timezone(parseDate(info[0] + info[1], 'YYYY-MM-DDHH:mm'), +8); + } else { + item.description = content('div.left_zw').text(); + const info = content('div.left-t') + .contents() + .filter(function () { + return this.type === 'text'; + }) + .text() + .split(' '); + item.pubDate = timezone(parseDate(info[0], 'YYYY年MM月DD日 HH:mm'), +8); + item.author = info[1] + content('a.source').text(); + } + return item; + }) + ) + ); + ctx.state.data = { + title: '中国新闻网', + link: currentUrl, + description: '中国新闻网(简称“中新网”),由中国新闻社主办,为中央重点新闻网站。', + language: 'zh-cn', + item: items, + }; +}; diff --git a/lib/v2/chinanews/maintainer.js b/lib/v2/chinanews/maintainer.js new file mode 100644 index 000000000..d50c937c0 --- /dev/null +++ b/lib/v2/chinanews/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['yuxinliu-alex'], +}; diff --git a/lib/v2/chinanews/radar.js b/lib/v2/chinanews/radar.js new file mode 100644 index 000000000..8a0fadfc5 --- /dev/null +++ b/lib/v2/chinanews/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'chinanews.com.cn': { + _name: '中国新闻网', + '.': [ + { + title: '最新', + docs: 'https://docs.rsshub.app/traditional-media.html#zhong-xin-wang', + source: ['/'], + target: '/chinanews', + }, + ], + }, +}; diff --git a/lib/v2/chinanews/router.js b/lib/v2/chinanews/router.js new file mode 100644 index 000000000..20c52b09d --- /dev/null +++ b/lib/v2/chinanews/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./index')); +};