diff --git a/docs/shopping.md b/docs/shopping.md index d2a2ddec1b7fff..a594d6af3ddf05 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -342,7 +342,7 @@ For instance, in + ## 小米 diff --git a/lib/router.js b/lib/router.js index c0ccc962013a46..adea8b8528fdad 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2762,9 +2762,6 @@ router.get('/adnmb/:pid', lazyloadRouteHandler('./routes/adnmb/index')); // MIT科技评论 router.get('/mittrchina/:type', lazyloadRouteHandler('./routes/mittrchina')); -// 消费者报道 -router.get('/ccreports/article', lazyloadRouteHandler('./routes/ccreports')); - // iYouPort router.get('/iyouport/article', lazyloadRouteHandler('./routes/iyouport')); router.get('/iyouport/:category?', lazyloadRouteHandler('./routes/iyouport')); diff --git a/lib/routes/ccreports/index.js b/lib/routes/ccreports/index.js deleted file mode 100644 index c5310f1968bb32..00000000000000 --- a/lib/routes/ccreports/index.js +++ /dev/null @@ -1,40 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const url = 'https://www.ccreports.com.cn/'; - const listData = await got.get(url); - const $1 = cheerio.load(listData.data); - const list = $1('.con h2'); - - ctx.state.data = { - title: '消费者报道', - link: url, - item: await Promise.all( - list - .slice(0, 5) - .map(async (index, item) => { - item = $1(item); - let fullTextGet = ''; - let fullText = ''; - let $2 = ''; - const contentUrl = item.find('a').attr('href'); - const description = await ctx.cache.tryGet(contentUrl, async () => { - fullTextGet = await got.get(contentUrl); - $2 = cheerio.load(fullTextGet.data); - $2('.h1p').remove(); - $2('.prenext').remove(); - $2('.pinglun').remove(); - fullText = $2('.content').html(); - return fullText; - }); - return { - title: item.find('a').text(), - description, - link: contentUrl, - }; - }) - .get() - ), - }; -}; diff --git a/lib/v2/ccreports/index.js b/lib/v2/ccreports/index.js new file mode 100644 index 00000000000000..36a374a64763d9 --- /dev/null +++ b/lib/v2/ccreports/index.js @@ -0,0 +1,41 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'https://www.ccreports.com.cn'; + +module.exports = async (ctx) => { + const listData = await got.get(rootUrl); + const $ = cheerio.load(listData.data); + const list = $('div.index-four-content > div.article-box') + .find('div.new-child') + .map((_, item) => ({ + title: $(item).find('p.new-title').text(), + link: new URL($(item).find('a').attr('href'), rootUrl).href, + author: $(item) + .find('p.new-desc') + .text() + .match(/作者:(.*?)\s/)[1], + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailData = await got.get(item.link); + const $ = cheerio.load(detailData.data); + item.description = $('div.pdbox').html(); + item.pubDate = timezone(parseDate($('div.newbox > div.newtit > p').text(), 'YYYY-MM-DD HH:mm:ss'), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '消费者报道', + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/ccreports/maintainer.js b/lib/v2/ccreports/maintainer.js new file mode 100644 index 00000000000000..0d6ad59bb045a0 --- /dev/null +++ b/lib/v2/ccreports/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/article': ['EsuRt', 'Fatpandac'], +}; diff --git a/lib/v2/ccreports/radar.js b/lib/v2/ccreports/radar.js new file mode 100644 index 00000000000000..f3b5b50de04b40 --- /dev/null +++ b/lib/v2/ccreports/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ccreports.com.cn': { + _name: '消费者报道', + www: [ + { + title: '要闻', + docs: 'https://docs.rsshub.app/shopping.html#xiao-fei-zhe-bao-dao-yao-wen', + source: ['/'], + target: '/ccreports/article', + }, + ], + }, +}; diff --git a/lib/v2/ccreports/router.js b/lib/v2/ccreports/router.js new file mode 100644 index 00000000000000..0261d8e9adea7c --- /dev/null +++ b/lib/v2/ccreports/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/article', require('./index')); +};