mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat: 增加人民日报环保频道 (#2299)
* 增加人民日报环保频道 * feat: 增加人民网环保频道 Co-authored-by: gewj <gewj@sinoyd.com>
This commit is contained in:
@@ -241,6 +241,11 @@ category 对应的关键词有
|
|||||||
### 观点
|
### 观点
|
||||||
|
|
||||||
<Route author="LogicJake" example="/people/opinion/223228" path="/people/opinion/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>
|
<Route author="LogicJake" example="/people/opinion/223228" path="/people/opinion/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>
|
||||||
|
|
||||||
|
### 环保频道
|
||||||
|
|
||||||
|
<Route author="zsimple" example="/people/env/74877" path="/people/env/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>
|
||||||
|
|
||||||
### 习近平系列重要讲话
|
### 习近平系列重要讲话
|
||||||
|
|
||||||
<Route author="LogicJake" example="/people/xjpjh" path="/people/xjpjh/:keyword?/:year?" :paramsDesc="['关键词,默认不填','年份,默认all']"/>
|
<Route author="LogicJake" example="/people/xjpjh" path="/people/xjpjh/:keyword?/:year?" :paramsDesc="['关键词,默认不填','年份,默认all']"/>
|
||||||
|
|||||||
@@ -1167,6 +1167,7 @@ router.get('/banyuetan/:name', require('./routes/banyuetan'));
|
|||||||
|
|
||||||
// 人民日报
|
// 人民日报
|
||||||
router.get('/people/opinion/:id', require('./routes/people/opinion'));
|
router.get('/people/opinion/:id', require('./routes/people/opinion'));
|
||||||
|
router.get('/people/env/:id', require('./routes/people/env'));
|
||||||
router.get('/people/xjpjh/:keyword?/:year?', require('./routes/people/xjpjh'));
|
router.get('/people/xjpjh/:keyword?/:year?', require('./routes/people/xjpjh'));
|
||||||
|
|
||||||
// gamersky
|
// gamersky
|
||||||
|
|||||||
82
lib/routes/people/env.js
Normal file
82
lib/routes/people/env.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const url = require('url');
|
||||||
|
const iconv = require('iconv-lite');
|
||||||
|
|
||||||
|
const host = 'http://env.people.com.cn';
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const id = ctx.params.id;
|
||||||
|
|
||||||
|
const link = `http://env.people.com.cn/GB/${id}/index.html`;
|
||||||
|
const response = await got.get(link, {
|
||||||
|
responseType: 'buffer',
|
||||||
|
});
|
||||||
|
response.data = iconv.decode(response.data, 'gbk');
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
let title = $('div.clearfix.w1000_320.d2nav').text();
|
||||||
|
title = title.replace(/ >> /g, '—');
|
||||||
|
|
||||||
|
const list = $('div.headingNews div.hdNews.clearfix')
|
||||||
|
.slice(0, 10)
|
||||||
|
.map(function() {
|
||||||
|
const info = {
|
||||||
|
title: $(this)
|
||||||
|
.find('strong > a')
|
||||||
|
.text(),
|
||||||
|
link: $(this)
|
||||||
|
.find('strong > a')
|
||||||
|
.attr('href'),
|
||||||
|
};
|
||||||
|
return info;
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const out = await Promise.all(
|
||||||
|
list.map(async (info) => {
|
||||||
|
const title = info.title;
|
||||||
|
const itemUrl = url.resolve(host, info.link);
|
||||||
|
|
||||||
|
const cache = await ctx.cache.get(itemUrl);
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(JSON.parse(cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await got.get(itemUrl, {
|
||||||
|
responseType: 'buffer',
|
||||||
|
});
|
||||||
|
response.data = iconv.decode(response.data, 'gbk');
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
let date = $('.clearfix.w1000_320.text_title .box01 .fl')
|
||||||
|
.text()
|
||||||
|
.split(/\s+/);
|
||||||
|
if (date.length > 0) {
|
||||||
|
date = date[0].replace(/(年|月)/g, '/').replace('日', ' ') + ':00';
|
||||||
|
console.log(date);
|
||||||
|
} else {
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
const description = $('div#rwb_zw')
|
||||||
|
.html()
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
title: title,
|
||||||
|
link: itemUrl,
|
||||||
|
description: description,
|
||||||
|
pubDate: new Date(date).toUTCString(),
|
||||||
|
};
|
||||||
|
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: title,
|
||||||
|
link: link,
|
||||||
|
item: out,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user