mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
@@ -1870,6 +1870,8 @@ Category 列表:
|
||||
|
||||
<route name="首页头条" author="HenryQW" example="/thepaper/featured" path="/thepaper/featured"/>
|
||||
|
||||
<route name="频道" author="xyqfer" example="/thepaper/channel/27224" path="/thepaper/channel/:id" :paramsDesc="['频道 id']"/>
|
||||
|
||||
### 联合早报
|
||||
|
||||
<route name="即时新闻" author="lengthmin" example="/zaobao/realtime/china" path="/zaobao/realtime/:type?" :paramsDesc="['分类, 缺省为中港台']">
|
||||
|
||||
@@ -704,6 +704,7 @@ router.get('/embassy/:country/:city?', require('./routes/embassy/index'));
|
||||
|
||||
// 澎湃新闻
|
||||
router.get('/thepaper/featured', require('./routes/thepaper/featured'));
|
||||
router.get('/thepaper/channel/:id', require('./routes/thepaper/channel'));
|
||||
|
||||
// 电影首发站
|
||||
router.get('/dysfz', require('./routes/dysfz/index'));
|
||||
|
||||
13
lib/routes/thepaper/channel.js
Normal file
13
lib/routes/thepaper/channel.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const link = `https://m.thepaper.cn/list_${id}`;
|
||||
const items = await utils.ProcessFeed(link, ctx);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `澎湃新闻频道 - ${id}`,
|
||||
link,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -1,66 +1,12 @@
|
||||
const cheerio = require('cheerio');
|
||||
const dayjs = require('dayjs');
|
||||
const url = require('url');
|
||||
const axios = require('../../utils/axios');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1',
|
||||
},
|
||||
});
|
||||
|
||||
const link = 'https://m.thepaper.cn/';
|
||||
|
||||
const res = await axios_ins.get(link);
|
||||
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('p.news_tit01, div.news_tit02')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const itemUrl = url.resolve(
|
||||
link,
|
||||
$(item)
|
||||
.find('a')
|
||||
.attr('href')
|
||||
);
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await axios_ins.get(itemUrl);
|
||||
const content = cheerio.load(res.data);
|
||||
const serverOffset = new Date().getTimezoneOffset() / 60;
|
||||
const single = {
|
||||
title: $(item)
|
||||
.find('a')
|
||||
.text(),
|
||||
guid: itemUrl,
|
||||
link: itemUrl.replace('https://m.', 'https://'),
|
||||
description: content('#v3cont_id > div.news_content > div.news_part_father > div > div:nth-child(1)').html(),
|
||||
pubDate: content('#v3cont_id > div.news_content > p:nth-child(3)').html()
|
||||
? dayjs(
|
||||
content('#v3cont_id > div.news_content > p:nth-child(3)')
|
||||
.html()
|
||||
.split(' ')[0]
|
||||
)
|
||||
.add(-8 - serverOffset, 'hour')
|
||||
.toISOString()
|
||||
: null,
|
||||
author: content('#v3cont_id > div.news_content > p:nth-child(2)').text(),
|
||||
};
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
const items = await utils.ProcessFeed(link, ctx);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '澎湃新闻 - 首页头条',
|
||||
link,
|
||||
item: out,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
60
lib/routes/thepaper/utils.js
Normal file
60
lib/routes/thepaper/utils.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const cheerio = require('cheerio');
|
||||
const dayjs = require('dayjs');
|
||||
const url = require('url');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = {
|
||||
ProcessFeed: async (link, ctx) => {
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1',
|
||||
},
|
||||
});
|
||||
|
||||
const res = await axios_ins.get(link);
|
||||
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('p.news_tit01, div.news_tit02')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
|
||||
return await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const itemUrl = url.resolve(
|
||||
link,
|
||||
$(item)
|
||||
.find('a')
|
||||
.attr('href')
|
||||
);
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await axios_ins.get(itemUrl);
|
||||
const content = cheerio.load(res.data);
|
||||
const serverOffset = new Date().getTimezoneOffset() / 60;
|
||||
const single = {
|
||||
title: $(item)
|
||||
.find('a')
|
||||
.text(),
|
||||
guid: itemUrl,
|
||||
link: itemUrl.replace('https://m.', 'https://'),
|
||||
description: content('#v3cont_id > div.news_content > div.news_part_father > div > div:nth-child(1)').html(),
|
||||
pubDate: content('#v3cont_id > div.news_content > p:nth-child(3)').html()
|
||||
? dayjs(
|
||||
content('#v3cont_id > div.news_content > p:nth-child(3)')
|
||||
.html()
|
||||
.split(' ')[0]
|
||||
)
|
||||
.add(-8 - serverOffset, 'hour')
|
||||
.toISOString()
|
||||
: null,
|
||||
author: content('#v3cont_id > div.news_content > p:nth-child(2)').text(),
|
||||
};
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user