fix(route): 腾讯企鹅号抓取失败 (#12653)

This commit is contained in:
miles 2023-06-13 18:49:42 +08:00 committed by GitHub
parent 1cf1d43eae
commit 75f545a9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 26 deletions

View File

@ -2,38 +2,40 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const config = require('@/config').value;
module.exports = async (ctx) => {
const mid = ctx.params.mid;
const response = await got(`https://pacaio.match.qq.com/om/mediaArticles?mid=${mid}&num=10&page=0`);
const reponse = response.data;
const title = reponse.mediainfo.name;
const description = reponse.mediainfo.intro;
const list = reponse.data;
const homePageInfoUrl = `https://i.news.qq.com/i/getUserHomepageInfo?chlid=${mid}`;
const userInfo = await ctx.cache.tryGet(homePageInfoUrl, async () => (await got(homePageInfoUrl)).data.userinfo);
const title = userInfo.nick;
const description = userInfo.user_desc;
const suid = encodeURIComponent(userInfo.suid);
const items = await Promise.all(
list.map((item) => {
const title = item.title;
const pubDate = timezone(parseDate(item.time), +8);
const itemUrl = item.vurl;
const author = item.source;
const abstract = item.abstract;
const newsListUrl = `https://i.news.qq.com/getSubNewsMixedList?guestSuid=${suid}&tabId=om_index`;
const news = await ctx.cache.tryGet(newsListUrl, async () => (await got(newsListUrl)).data.newslist, config.cache.routeExpire, false);
return ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl);
const $ = cheerio.load(response.data);
const article = $('div.content-article');
const items = news.map((item) => {
const title = item.title;
const pubDate = timezone(parseDate(item.time), +8);
const itemUrl = item.url;
const author = item.source;
const abstract = item.abstract;
return {
title,
description: article.html() || abstract,
link: itemUrl,
author,
pubDate,
};
});
})
);
return ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl);
const $ = cheerio.load(response.data);
const article = $('#ArticleContent');
return {
title,
description: article.html() || abstract,
link: itemUrl,
author,
pubDate,
};
});
});
ctx.state.data = {
title,