Skip to content

Commit

Permalink
rss:add infzm news (DIYgod#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
RANPOX authored and DIYgod committed May 21, 2018
1 parent c33c990 commit 677b400
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
* 频道
* 爱奇艺
* 动漫
* 南方周末
* 新闻

## 参与我们

Expand Down
14 changes: 14 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
3 changes: 3 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
48 changes: 48 additions & 0 deletions routes/infzm/news.js
Original file line number Diff line number Diff line change
@@ -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()}<img referrerpolicy="no-referrer" src="${item.find('img').attr('src')}">`,
pubDate: date.toUTCString(),
link: item.find('a').attr('href'),
};
})
.get(),
};
};

0 comments on commit 677b400

Please sign in to comment.