From 9231dabc747a6ba942b483a5bff6880cedbcc59e Mon Sep 17 00:00:00 2001 From: Georeth Chow Date: Tue, 27 Nov 2018 14:36:41 +0800 Subject: [PATCH] add zongheng.com (#1200) close #439 --- docs/README.md | 4 ++++ router.js | 3 +++ routes/zongheng/chapter.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 routes/zongheng/chapter.js diff --git a/docs/README.md b/docs/README.md index f347c5b3f6..2db2d5fab9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2047,6 +2047,10 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 +### 纵横 + + + ### 刺猬猫 diff --git a/router.js b/router.js index 6d431f8dee..c366607708 100644 --- a/router.js +++ b/router.js @@ -409,6 +409,9 @@ 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('/zongheng/chapter/:id', require('./routes/zongheng/chapter')); + // 刺猬猫 router.get('/ciweimao/chapter/:id', require('./routes/ciweimao/chapter')); diff --git a/routes/zongheng/chapter.js b/routes/zongheng/chapter.js new file mode 100644 index 0000000000..8452a63c39 --- /dev/null +++ b/routes/zongheng/chapter.js @@ -0,0 +1,33 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const [$, $home] = (await Promise.all([axios.get(`http://book.zongheng.com/showchapter/${id}.html`), axios.get(`http://book.zongheng.com/book/${id}.html`)])).map((res) => cheerio.load(res.data)); + const date_re = /更新时间:(.*)$/; + const cover_url = $home('.book-img img').attr('src'); + const description = $home('.book-dec').text(); + const name = $('.book-meta h1').text(); + + const chapters = $('.volume-list li a'); + const items = []; + for (let i = 0; i < chapters.length; i++) { + const chapter = chapters.eq(i); + const date_string = date_re.exec(chapter.attr('title'))[1]; + + items.push({ + title: chapter.text(), + pubDate: new Date(date_string).toUTCString(), + link: chapter.attr('href'), + }); + } + + ctx.state.data = { + title: `纵横 ${name}`, + link: `http://book.zongheng.com/book/${id}.html`, + description, + image: cover_url, + item: items, + }; +};