From 1ddc2b30e99abf7b3d9975e91cafc7a2ff537541 Mon Sep 17 00:00:00 2001 From: NeverBehave Date: Tue, 28 Apr 2020 11:46:11 -0400 Subject: [PATCH] fix: [Xiaohongshu] remove Dom object from description (#4594) --- lib/routes/xiaohongshu/board.js | 4 +--- lib/routes/xiaohongshu/user.js | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/routes/xiaohongshu/board.js b/lib/routes/xiaohongshu/board.js index 903594ef2..6fadc56f2 100644 --- a/lib/routes/xiaohongshu/board.js +++ b/lib/routes/xiaohongshu/board.js @@ -1,13 +1,11 @@ const { getContent } = require('@/routes/xiaohongshu/util'); -const JSON5 = require('json5'); - module.exports = async (ctx) => { const url = `https://www.xiaohongshu.com/board/${ctx.params.board_id}`; const content = await getContent(url); const regex = /_SSR_STATE__\S*=([\s\S]+)<\/script>/gm; const match = regex.exec(content); - const main = JSON5.parse(match[1]).Main; + const main = JSON.parse(match[1]).Main; const albumInfo = main.albumInfo; const title = `${albumInfo.name}`; diff --git a/lib/routes/xiaohongshu/user.js b/lib/routes/xiaohongshu/user.js index 047020ec2..af658dfea 100644 --- a/lib/routes/xiaohongshu/user.js +++ b/lib/routes/xiaohongshu/user.js @@ -1,7 +1,6 @@ const { getContent } = require('@/routes/xiaohongshu/util'); const cheerio = require('cheerio'); -const JSON5 = require('json5'); module.exports = async (ctx) => { const userId = ctx.params.user_id; @@ -10,10 +9,10 @@ module.exports = async (ctx) => { const content = await getContent(url); const $ = cheerio.load(content); - const description = $('head title'); + const description = $('head title').html(); const regex = /_SSR_STATE__\S*=([\s\S]+)<\/script>/gm; const match = regex.exec(content); - const main = JSON5.parse(match[1]).Main; + const main = JSON.parse(match[1]).Main; const userDetail = main.userDetail; if (category === 'notes') { const list = main.notesDetail;