fix(route/tophub): fix selectors (#20408)
* fix(route/tophub): fix selectors * fix(route/tophub): include image in response
This commit is contained in:
parent
64399c50d1
commit
ec0d80d91f
|
|
@ -1,5 +1,5 @@
|
|||
import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { config } from '@/config';
|
||||
|
||||
|
|
@ -36,28 +36,31 @@ async function handler(ctx) {
|
|||
const id = ctx.req.param('id');
|
||||
|
||||
const link = `https://tophub.today/n/${id}`;
|
||||
const response = await got.get(link, {
|
||||
const response = await ofetch(link, {
|
||||
headers: {
|
||||
Referer: 'https://tophub.today',
|
||||
Cookie: config.tophub.cookie,
|
||||
Cookie: config.tophub?.cookie ?? '',
|
||||
},
|
||||
});
|
||||
const $ = load(response.data);
|
||||
const $ = load(response);
|
||||
|
||||
const title = $('div.Xc-ec-L.b-L').text().trim();
|
||||
const title = $('.tt h3').text().trim();
|
||||
|
||||
const out = $('div.Zd-p-Sc > div:nth-child(1) tr')
|
||||
const out = $('.rank-all-item:not(.history-content) .jc-c tr')
|
||||
.toArray()
|
||||
.map((e) => {
|
||||
const info = {
|
||||
title: $(e).find('td.al a').text(),
|
||||
link: $(e).find('td.al a').attr('href'),
|
||||
title: $(e).find('td a').first().text(),
|
||||
link: $(e).find('td a').first().attr('href'),
|
||||
description: $(e).find('.ws').text().trim(),
|
||||
};
|
||||
return info;
|
||||
});
|
||||
|
||||
return {
|
||||
title,
|
||||
description: $('.tt p').text().trim(),
|
||||
image: $('.ii img').attr('src'),
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { Route } from '@/types';
|
||||
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { config } from '@/config';
|
||||
import path from 'node:path';
|
||||
import { art } from '@/utils/render';
|
||||
import xxhash from 'xxhash-wasm';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/list/:id',
|
||||
|
|
@ -34,26 +35,27 @@ export const route: Route = {
|
|||
maintainers: ['akynazh'],
|
||||
handler,
|
||||
description: `::: tip
|
||||
将榜单条目集合到一个列表中,可避免推送大量条目,更符合阅读习惯且有热度排序,推荐使用。
|
||||
将榜单条目集合到一个列表中,且有热度排序,可避免推送大量条目。
|
||||
:::`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const { h64ToString } = await xxhash();
|
||||
const id = ctx.req.param('id');
|
||||
const link = `https://tophub.today/n/${id}`;
|
||||
const response = await got.get(link, {
|
||||
const response = await ofetch(link, {
|
||||
headers: {
|
||||
Referer: 'https://tophub.today',
|
||||
Cookie: config.tophub.cookie,
|
||||
Cookie: config.tophub?.cookie ?? '',
|
||||
},
|
||||
});
|
||||
const $ = load(response.data);
|
||||
const title = $('div.Xc-ec-L.b-L').text().trim();
|
||||
const items = $('div.Zd-p-Sc > div:nth-child(1) tr')
|
||||
const $ = load(response);
|
||||
const title = $('.tt h3').text().trim();
|
||||
const items = $('.rank-all-item:not(.history-content) .jc-c tr')
|
||||
.toArray()
|
||||
.map((e) => ({
|
||||
title: $(e).find('td.al a').text().trim(),
|
||||
link: $(e).find('td.al a').attr('href'),
|
||||
title: $(e).find('td a').text().trim(),
|
||||
link: $(e).find('td a').attr('href'),
|
||||
heatRate: $(e).find('td:nth-child(3)').text().trim(),
|
||||
}));
|
||||
const combinedTitles = items.map((item) => item.title).join('');
|
||||
|
|
@ -61,13 +63,15 @@ async function handler(ctx) {
|
|||
|
||||
return {
|
||||
title,
|
||||
description: $('.tt p').text().trim(),
|
||||
image: $('.ii img').attr('src'),
|
||||
link,
|
||||
item: [
|
||||
{
|
||||
title,
|
||||
link,
|
||||
description: renderRank,
|
||||
guid: combinedTitles,
|
||||
guid: h64ToString(combinedTitles),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue