From 69a88702301022884e46988a768f6dc2360b5328 Mon Sep 17 00:00:00 2001 From: jjeejj Date: Mon, 7 May 2018 22:44:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E8=80=85=20=E5=A4=B4=E6=9D=A1=20RSS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 18 ++++++++++++++++- router.js | 4 ++++ routes/toutiao/today.js | 35 +++++++++++++++++++++++++++++++++ routes/toutiao/user.js | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 routes/toutiao/today.js create mode 100644 routes/toutiao/user.js diff --git a/docs/README.md b/docs/README.md index e76445d9b..0766dfa48 100644 --- a/docs/README.md +++ b/docs/README.md @@ -504,4 +504,20 @@ key: 产品密钥 路由: `/biquge/novel/latestchapter/:id` -参数: id,小说 id,可在对应小说页 URL 中找到 \ No newline at end of file +参数: id,小说 id,可在对应小说页 URL 中找到 + +## 开发者头条 + +### 今天头条 + +举例: [https://rss.now.sh/toutiao/today](https://rss.now.sh/toutiao/today) + +路由: `/toutiao/today` + +### 独家号 + +举例: [https://rss.now.sh/toutiao/user/:id](https://rss.now.sh/toutiao/user/:id) + +路由: `/toutiao/user/:id` + +参数: id,独家号 id,可在对应独家号页 URL 中找到 diff --git a/router.js b/router.js index 6613dc411..2aab05ce4 100644 --- a/router.js +++ b/router.js @@ -87,4 +87,8 @@ router.get('/tucaoqq/post/:project/:key', require('./routes/tucaoqq/post')); // 笔趣阁 router.get('/biquge/novel/latestchapter/:id', require('./routes/biquge/chapter')); +// 开发者头条 +router.get('/toutiao/today', require('./routes/toutiao/today')); +router.get('/toutiao/user/:id', require('./routes/toutiao/user')); + module.exports = router; diff --git a/routes/toutiao/today.js b/routes/toutiao/today.js new file mode 100644 index 000000000..e2fb65b1a --- /dev/null +++ b/routes/toutiao/today.js @@ -0,0 +1,35 @@ +const axios = require('axios'); +const template = require('../../utils/template'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +const baseUrl = 'https://toutiao.io' +module.exports = async (ctx)=>{ + const response = await axios({ + method:'get', + url:baseUrl, + headers: { + 'User-Agent': config.ua, + 'Host':'toutiao.io' + }, + responseType: 'text' + }); + const $ = cheerio.load(response.data); + const title = $('#daily').find('.date>span').eq(0).text() + ' ' + $('#daily').find('.date>small').eq(0).text(); + + const list = $('.posts>.post', '#daily'); + const article_item = []; + for(let i=0;i{ + const id = ctx.params.id; + requestUrl = requestUrl.replace('userID',id); + const response = await axios({ + method:'get', + url:requestUrl, + headers: { + 'User-Agent': config.ua, + 'Host':'toutiao.io' + }, + responseType: 'text' + }); + const $ = cheerio.load(response.data); + const image = $('#main').find('.text-center>.subject-cover>img').eq(0).attr('src'); + const link = requestUrl; + const title = $('#main').find('.text-center>h3').eq(0).text(); + const description = $('#main').find('.social-share-button').eq(0).attr('data-title'); + + const list = $('.posts>.post', '#main'); + const article_item = []; + for(let i=0;i Date: Tue, 8 May 2018 20:53:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- routes/toutiao/user.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0766dfa48..08ccba1b9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -516,7 +516,7 @@ key: 产品密钥 ### 独家号 -举例: [https://rss.now.sh/toutiao/user/:id](https://rss.now.sh/toutiao/user/:id) +举例: [https://rss.now.sh/toutiao/user/140544](https://rss.now.sh/toutiao/user/140544) 路由: `/toutiao/user/:id` diff --git a/routes/toutiao/user.js b/routes/toutiao/user.js index fdcbc4ee6..2b81de04d 100644 --- a/routes/toutiao/user.js +++ b/routes/toutiao/user.js @@ -4,10 +4,9 @@ const cheerio = require('cheerio'); const config = require('../../config'); const baseUrl = 'https://toutiao.io'; -let requestUrl = `${baseUrl}/subjects/userID?f=new` module.exports = async (ctx)=>{ const id = ctx.params.id; - requestUrl = requestUrl.replace('userID',id); + let requestUrl = `${baseUrl}/subjects/${id}?f=new`; const response = await axios({ method:'get', url:requestUrl,