fix(route): taoguba (#11070)

This commit is contained in:
Tony 2022-10-12 16:53:25 +04:00 committed by GitHub
parent ada7037148
commit ce8d3d3184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 17 deletions

View File

@ -15,6 +15,7 @@ module.exports = async (ctx) => {
});
const $ = cheerio.load(response.data);
const author = $('meta[property="og:author"]').attr('content');
let items = $('.tittle_data')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
@ -27,6 +28,7 @@ module.exports = async (ctx) => {
return {
title: a.text(),
link: `${rootUrl}/${a.attr('href')}`,
author,
};
});
@ -37,14 +39,35 @@ module.exports = async (ctx) => {
method: 'get',
url: item.link,
});
if (detailResponse.url.startsWith('https://www.taoguba.com.cn/topic/transfer')) {
item.description = '登录后查看完整文章';
return item;
}
const content = cheerio.load(detailResponse.data);
content('#videoImg').remove();
content('img').each((_, img) => {
if (img.attribs.src2) {
img.attribs.src = img.attribs.src2;
delete img.attribs.src2;
delete img.attribs['data-original'];
}
});
item.description = content('#first').html();
item.author = content('.pcyclname').first().text();
item.pubDate = timezone(parseDate(content('.pcyclspan').first().text()), +8);
item.pubDate = timezone(
parseDate(
content('.article-data span')
.eq(1)
.text()
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)
),
+8
);
item.category = content('.article-topic-list span')
.toArray()
.map((item) => $(item).text().trim());
return item;
})
@ -52,7 +75,9 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `淘股吧 - ${$('meta[property="og:author"]').attr('content')}`,
title: `淘股吧 - ${author}`,
description: $('meta[http-equiv="description"]').attr('content'),
image: $('meta[property="og:image"]').attr('content'),
link: currentUrl,
item: items,
};

View File

@ -16,17 +16,19 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
let items = $('.p_list01, .blk, .cov')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
let items = $('.items-comment-list')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 70)
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
const a = item.find('.items-list-tittle a');
a.find('b').remove();
return {
title: a.text(),
link: `${rootUrl}/${a.attr('href')}`,
author: item.find('.items-list-user a').text().trim(),
};
});
@ -37,30 +39,43 @@ module.exports = async (ctx) => {
method: 'get',
url: item.link,
});
if (detailResponse.url.startsWith('https://www.taoguba.com.cn/topic/transfer')) {
item.description = '登录后查看完整文章';
return item;
}
const content = cheerio.load(detailResponse.data);
content('#videoImg').remove();
content('img').each((_, img) => {
if (img.attribs.src2) {
img.attribs.src = img.attribs.src2;
delete img.attribs.src2;
delete img.attribs['data-original'];
}
});
item.description = content('#first').html();
item.author = content('.pcyclname').first().text();
item.pubDate = timezone(parseDate(content('.pcyclspan').first().text()), +8);
item.pubDate = timezone(
parseDate(
content('.article-data span')
.eq(1)
.text()
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)
),
+8
);
item.category = content('.article-topic-list span')
.toArray()
.map((item) => $(item).text().trim());
return item;
})
)
);
let title = '';
for (const t of $('.NewH_bot_title3 a').toArray()) {
if ($(t).attr('href') === currentUrl) {
title = $(t).text();
break;
}
}
ctx.state.data = {
title: `淘股吧 - ${title}`,
title: $('head title').text().trim().split('_')[0],
link: currentUrl,
item: items,
};