From c4e31a3dc4ee20f9b7c84f2f6c64a4d45d6bfb9a Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Tue, 28 Aug 2018 11:11:17 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E6=87=82=E7=90=83=E5=B8=9D=E8=B6=B3?= =?UTF-8?q?=E7=90=83=E8=B5=9B=E6=9E=9C=20(#554)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + docs/README.md | 10 ++++++ router.js | 3 +- routes/dongqiudi/{index.js => daily.js} | 0 routes/dongqiudi/result.js | 47 +++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) rename routes/dongqiudi/{index.js => daily.js} (100%) create mode 100644 routes/dongqiudi/result.js diff --git a/README.md b/README.md index 65110da97..2e8c822ad 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 讨论区 - 懂球帝 - 早报 + - 足球赛果 - 维基百科 - 中国大陆新闻动态 - 雪球 diff --git a/docs/README.md b/docs/README.md index a942fdafc..1c8d34818 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1835,6 +1835,16 @@ id, 专辑 id, 可在对应**专辑**页面的 URL 中找到 参数:无 +### 足球赛果 + +举例: 皇家马德里:[https://rsshub.app/dongqiudi/result/50001755](https://rsshub.app/dongqiudi/result/50001755) + +路由: `/dongqiudi/result/:team` + +参数: + +team,球队 id,可在[懂球帝数据](https://www.dongqiudi.com/data)中找到 + ## 维基百科 ### 中国大陆新闻动态 diff --git a/router.js b/router.js index 0cce4473a..16b975254 100755 --- a/router.js +++ b/router.js @@ -387,7 +387,8 @@ router.get('/namoc/exhibition', require('./routes/namoc/exhibition')); router.get('/namoc/specials', require('./routes/namoc/specials')); // 懂球帝 -router.get('/dongqiudi/daily', require('./routes/dongqiudi/index')); +router.get('/dongqiudi/daily', require('./routes/dongqiudi/daily')); +router.get('/dongqiudi/result/:team', require('./routes/dongqiudi/result')); // 维基百科 router.get('/wikipedia/mainland', require('./routes/wikipedia/mainland')); diff --git a/routes/dongqiudi/index.js b/routes/dongqiudi/daily.js similarity index 100% rename from routes/dongqiudi/index.js rename to routes/dongqiudi/daily.js diff --git a/routes/dongqiudi/result.js b/routes/dongqiudi/result.js new file mode 100644 index 000000000..62b078485 --- /dev/null +++ b/routes/dongqiudi/result.js @@ -0,0 +1,47 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const team = ctx.params.team; + const link = `https://www.dongqiudi.com/team/${team}.html`; + + const response = await axios.get(link); + const $ = cheerio.load(response.data); + const teamName = $('h1.name').text(); + const list = $('table.schedule_list tr.stat_list'); + const out = []; + + for (let i = 0; i < list.length; i++) { + const $ = cheerio.load(list[i]); + + const score = $('td:nth-of-type(5)') + .text() + .trim(); + + if (score !== '-') { + const time = $('td.match_time_hidden').text(); + const type = $('td.gameweek').text(); + const home = $('td:nth-of-type(4)') + .text() + .trim(); + const away = $('td:nth-of-type(6)') + .text() + .trim(); + const title = `${type} ${home} ${score} ${away}`; + + const single = { + title, + link, + pubDate: new Date(time), + guid: title, + }; + out.push(single); + } + } + + ctx.state.data = { + title: `${teamName} 比赛结果`, + link, + item: out.slice(out.length - 10, out.length), + }; +};