diff --git a/README.md b/README.md index e3e1a78c4..4c3c31877 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 起点 - 章节 - 讨论区 +- 懂球帝 + - 早报 diff --git a/docs/README.md b/docs/README.md index 982922eee..24f989802 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1626,3 +1626,13 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 路由: `/qidian/forum/:id` 参数: id,小说 id,可在对应小说页 URL 中找到 + +## 懂球帝 + +### 早报 + +举例: [https://rsshub.app/dongqiudi/daily](https://rsshub.app/dongqiudi/daily) + +路由: `/dongqiudi/daily` + +参数:无 diff --git a/router.js b/router.js index 1a15bea29..0d8491abc 100755 --- a/router.js +++ b/router.js @@ -372,4 +372,7 @@ router.get('/keep/user/:id', require('./routes/keep/user')); router.get('/qidian/chapter/:id', require('./routes/qidian/chapter')); router.get('/qidian/forum/:id', require('./routes/qidian/forum')); +// 懂球帝 +router.get('/dongqiudi/daily', require('./routes/dongqiudi/index')); + module.exports = router; diff --git a/routes/dongqiudi/index.js b/routes/dongqiudi/index.js new file mode 100644 index 000000000..d38f3a279 --- /dev/null +++ b/routes/dongqiudi/index.js @@ -0,0 +1,61 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); +const cheerio = require('cheerio'); + +const _axios_client = axios.create({ + headers: { + 'User-Agent': config.ua, + }, +}); + +module.exports = async (ctx) => { + const response = await _axios_client.get('http://www.dongqiudi.com/special/48'); + + const $ = cheerio.load(response.data); + + const host = 'http://www.dongqiudi.com'; + + const list = $('.detail.special ul li h3').slice(0, 10); + const out = []; + const proList = []; + + for (let i = 0; i < list.length; i++) { + const $ = cheerio.load(list[i]); + const title = $('a').text(); + const itemUrl = host + $('a').attr('href'); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + out.push(JSON.parse(cache)); + continue; + } + const single = { + title, + link: itemUrl, + guid: itemUrl, + }; + + try { + const es = _axios_client.get(itemUrl); + proList.push(es); + out.push(single); + } catch (err) { + console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + } + } + + const responses = await axios.all(proList); + for (let i = 0; i < responses.length; i++) { + const $ = cheerio.load(responses[i].data); + const full = $('div.detail'); + + out[i].description = full.find('div:nth-of-type(1)').html(); + out[i].author = full.find('span.name').text(); + out[i].pubDate = new Date(full.find('span.time').text()).toUTCString(); + ctx.cache.set(out[i].link, JSON.stringify(out[i]), 24 * 60 * 60); + } + ctx.state.data = { + title: '懂球帝早报', + link: 'http://www.dongqiudi.com/special/48', + item: out, + }; +};