From a99c1b1fbb290757e54d04dfd2eb1f96dfbeafb4 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 22 Apr 2019 13:19:44 +0800 Subject: [PATCH] fix wasi --- lib/routes/tencent/wechat/wasi.js | 44 ++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/routes/tencent/wechat/wasi.js b/lib/routes/tencent/wechat/wasi.js index 50f2c3019d..2064466516 100644 --- a/lib/routes/tencent/wechat/wasi.js +++ b/lib/routes/tencent/wechat/wasi.js @@ -1,35 +1,37 @@ const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const id = ctx.params.id; const response = await axios({ method: 'get', - url: `https://q.qnmlgb.tech/w/api/articles?_ls=&_fmt=authorSimple&_page=author&_author_id=${id}&_sub_tab=&_tab=author`, - headers: { - Referer: `https://w.qnmlgb.tech/authors/${id}/`, - }, + url: `https://wx.qnmlgb.tech/authors/${id}`, }); - const rawData = response.data.result.articles; - const data = []; - - for (let i = 0; i < rawData.length; i++) { - const subArticles = rawData[i].sub_articles; - for (let j = 0; j < subArticles.length; j++) { - data.push(subArticles[j]); - } - } + const $ = cheerio.load(response.data); + const list = $('.ae'); ctx.state.data = { - title: `${rawData[0].author.nickname}微信公众号`, + title: `${$('#spider > div:nth-child(1) > div:nth-child(1)') + .text() + .trim()}微信公众号`, link: `https://w.qnmlgb.tech/authors/${id}/`, - description: rawData[0].author.profile_desc, - item: data.map((item) => ({ - title: item.article.title, - description: `${item.article.digest}`, - pubDate: new Date(item.article.datetime * 1000).toUTCString(), - link: item.article.content_url, - })), + description: $('#spider > div:nth-child(2)') + .text() + .trim(), + item: + list && + list + .map((i, ele) => { + const $ = cheerio.load(ele); + return { + title: $('.pretty') + .text() + .trim(), + link: $('a').attr('href'), + }; + }) + .get(), }; };