diff --git a/README.md b/README.md index aa745e7e3..673ffaf0f 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 * 频道 * 爱奇艺 * 动漫 +* 南方周末 + * 新闻 ## 参与我们 diff --git a/docs/README.md b/docs/README.md index eb4f4e136..485a32a7c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -769,3 +769,17 @@ key: 产品密钥 路由: `/iqiyi/dongman/:id` 参数: id,动漫 id,可在该动漫主页 URL 中找到(不包括`.html`) + +##南方周末 + +### 新闻分类 + +举例:[https://rsshub.app/infzm/5](https://rsshub.app/infzm/5) + +路由: `/infzm/:id` + +参数: id,南方周末内容分区 id,可在该内容分区的 URL 中找到(即http://www.infzm.com/contents/:id),注意 contents 为内容分区,content 为文章页,添加前请留意。下面给出部分参考: + +| 全站 | 新闻 | 经济 | 文化 | 评论 | 图片 | 生活 | 时政 | 社会 | 科技 | 绿色 | 头条 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| 0 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 1374 | 2553 | diff --git a/router.js b/router.js index 905a79832..7115e4916 100644 --- a/router.js +++ b/router.js @@ -205,4 +205,7 @@ router.get('/geektime/column/:cid', require('./routes/geektime/column')); // 爱奇艺 router.get('/iqiyi/dongman/:id', require('./routes/iqiyi/dongman')); +// infzm +router.get('/infzm/:id', require('./routes/infzm/news')); + module.exports = router; diff --git a/routes/infzm/news.js b/routes/infzm/news.js new file mode 100644 index 000000000..70db8c42a --- /dev/null +++ b/routes/infzm/news.js @@ -0,0 +1,48 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +const baseUrl = 'http://www.infzm.com/contents/'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + const url = `${baseUrl}${id}`; + const response = await axios({ + method: 'get', + url: url, + headers: { + 'User-Agent': config.ua, + Referer: url, + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('article'); + ctx.state.data = { + title: `${$('title').text()}-${$('#sortName') + .find('a') + .text()}`, + link: url, + description: $('meta[name="description"]').attr('content'), + item: + list && + list + .map((item, index) => { + item = $(index); + const info = item + .find('div.clearfix>div>p.articleInfo') + .text() + .trim() + .split(/\s+/); + const date = new Date(`${info.slice(-2)[0]}T${info.slice(-1)[0]}`); + return { + title: item.find('div.articleTitle>h>a').text(), + description: `${item.find('div.clearfix>div>p.intro').text()}`, + pubDate: date.toUTCString(), + link: item.find('a').attr('href'), + }; + }) + .get(), + }; +};