Add 好奇心日报 (#1735)

This commit is contained in:
Wenhu
2019-03-12 19:02:49 +08:00
committed by DIYgod
parent 03f47d9400
commit 1a8b5b3614
5 changed files with 179 additions and 0 deletions
+10
View File
@@ -654,6 +654,12 @@ RSSHub 提供下列 API 接口:
<route name="板塊帖子" author="HenryQW" example="/dcard/funny/popular" path="/dcard/:section/:type?" :paramsDesc="['板塊名稱,URL 中獲得', '排序,popular 熱門;latest 最新,默認為 latest']"/>
### 好奇心日报
<route name="分类" author="WenhuWee" example="/qdaily/category/5" path="/qdaily/category/:id?" :paramsDesc="['分类id,可在分类URL找到']"/>
<route name="栏目" author="WenhuWee" example="/qdaily/column/59" path="/qdaily/column/:id?" :paramsDesc="['栏目id,可在栏目URL找到']"/>
## 编程
### 掘金
@@ -2102,6 +2108,10 @@ Category 列表:
<route name="栏目" author="DIYgod" example="/bjnews/realtime" path="/bjnews/:category" :paramsDesc="['新京报的栏目名, 点击对应栏目后在地址栏找到']"/>
### 界面新闻
<route name="栏目" author="WenhuWee" example="/jiemian/list/79" path="/jiemian/list/:category" :paramsDesc="['对应栏目后在地址栏找到']"/>
### 澎湃新闻
<route name="首页头条" author="HenryQW" example="/thepaper/featured" path="/thepaper/featured"/>
+7
View File
@@ -276,6 +276,13 @@ router.get('/jike/daily', require('./routes/jike/daily'));
// 极客时间
router.get('/geektime/column/:cid', require('./routes/geektime/column'));
// 界面新闻
router.get('/jiemian/list/:cid', require('./routes/jiemian/list.js'));
// 好奇心日报
router.get('/qdaily/column/:id', require('./routes/qdaily/column'));
router.get('/qdaily/category/:id', require('./routes/qdaily/category'));
// 爱奇艺
router.get('/iqiyi/dongman/:id', require('./routes/iqiyi/dongman'));
+60
View File
@@ -0,0 +1,60 @@
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const url = `https://www.jiemian.com/lists/${ctx.params.cid}.html`;
const res = await axios.get(url);
const $ = cheerio.load(res.data);
const list = $('.news-view').get();
const proList = [];
const indexList = [];
const out = await Promise.all(
list.map(async (item, i) => {
const $ = cheerio.load(item);
const time = $('.date').text();
let title = $('.news-img a').attr('title');
if (!title) {
title = $('a').text();
}
const itemUrl = $('.news-img a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title,
pubDate: new Date(time).toUTCString(),
link: itemUrl,
guid: itemUrl,
};
proList.push(axios.get(itemUrl));
indexList.push(i);
return Promise.resolve(single);
})
);
const responses = await axios.all(proList);
for (let i = 0; i < responses.length; i++) {
const res = responses[i];
const $ = cheerio.load(res.data);
let time = $('.article-info span')
.eq(1)
.text();
if (!time) {
time = $('.article-header .info .date').text();
}
out[indexList[i]].pubDate = new Date(time).toUTCString();
const content = $('.article-view .article-main').html();
out[indexList[i]].description = content;
ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i]), 24 * 60 * 60);
}
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};
+51
View File
@@ -0,0 +1,51 @@
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const url = `http://www.qdaily.com/categories/${ctx.params.id}.html`;
const res = await axios.get(url);
const $ = cheerio.load(res.data);
const list = $('.article').get();
const proList = [];
const indexList = [];
const out = await Promise.all(
list.map(async (item, i) => {
const $ = cheerio.load(item);
const time = $('.smart-date').attr('data-origindate');
let title = $('.title').text();
if (!title) {
title = $('.smart-dotdotdot').text();
}
const itemUrl = $('a').attr('href');
const allUrl = `http://www.qdaily.com${itemUrl}`;
const cache = await ctx.cache.get(allUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title,
pubDate: new Date(time).toUTCString(),
link: allUrl,
guid: allUrl,
};
proList.push(axios.get(allUrl));
indexList.push(i);
return Promise.resolve(single);
})
);
const responses = await axios.all(proList);
for (let i = 0; i < responses.length; i++) {
const res = responses[i];
const $ = cheerio.load(res.data);
out[indexList[i]].description = $('.main .com-article-detail').html();
ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i]), 24 * 60 * 60);
}
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};
+51
View File
@@ -0,0 +1,51 @@
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const url = `http://www.qdaily.com/special_columns/${ctx.params.id}.html`;
const res = await axios.get(url);
const $ = cheerio.load(res.data);
const list = $('.article').get();
const proList = [];
const indexList = [];
const out = await Promise.all(
list.map(async (item, i) => {
const $ = cheerio.load(item);
const time = $('.smart-date').attr('data-origindate');
let title = $('.title').text();
if (!title) {
title = $('.smart-dotdotdot').text();
}
const itemUrl = $('a').attr('href');
const allUrl = `http://www.qdaily.com${itemUrl}`;
const cache = await ctx.cache.get(allUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title,
pubDate: new Date(time).toUTCString(),
link: allUrl,
guid: allUrl,
};
proList.push(axios.get(allUrl));
indexList.push(i);
return Promise.resolve(single);
})
);
const responses = await axios.all(proList);
for (let i = 0; i < responses.length; i++) {
const res = responses[i];
const $ = cheerio.load(res.data);
out[indexList[i]].description = $('.main .com-article-detail').html();
ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i]), 24 * 60 * 60);
}
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};