From 644a86962db99e13ff98880c782053f461703218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Mon, 31 Dec 2018 01:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0:=20nga=20=E5=B8=96=E5=AD=90?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20(#1324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1311 --- docs/README.md | 2 ++ lib/router.js | 1 + lib/routes/nga/post.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lib/routes/nga/post.js diff --git a/docs/README.md b/docs/README.md index ab27e4d510..11e1bae258 100644 --- a/docs/README.md +++ b/docs/README.md @@ -575,6 +575,8 @@ RSSHub 提供下列 API 接口: + + ### Facebook diff --git a/lib/router.js b/lib/router.js index ea16999bb1..4c25a72e21 100644 --- a/lib/router.js +++ b/lib/router.js @@ -886,6 +886,7 @@ router.get('/coolbuy/newest', require('./routes/coolbuy/newest')); // NGA router.get('/nga/forum/:fid', require('./routes/nga/forum')); +router.get('/nga/post/:tid', require('./routes/nga/post')); // JavBus router.get('/javbus/home', require('./routes/javbus/home')); diff --git a/lib/routes/nga/post.js b/lib/routes/nga/post.js new file mode 100644 index 0000000000..8221a57797 --- /dev/null +++ b/lib/routes/nga/post.js @@ -0,0 +1,47 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const { tid } = ctx.params; + const link = `https://nga.178.com/read.php?tid=${tid}&rand=${Math.random() * 1000}`; + const timestamp = Math.floor(Date.now() / 1000); + const response = await axios({ + method: 'get', + url: link, + responseType: 'arraybuffer', + headers: { + Cookie: `guestJs=${timestamp};`, + }, + }); + + const htmlString = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(htmlString); + const title = $('title').text() || ''; + const description = $('#postcontentandsubject0').html() || ''; + let pubDate = new Date($('#postdate0').text()).toUTCString(); + + if ($('#alertc0').length > 0) { + const matches = htmlString.match(/<\/span>