fix(route/tophub): fix selectors (#20408)

* fix(route/tophub): fix selectors

* fix(route/tophub): include image in response
This commit is contained in:
Tony 2025-11-03 04:18:27 +08:00 committed by GitHub
parent 64399c50d1
commit ec0d80d91f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 18 deletions

View File

@ -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,
};

View File

@ -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),
},
],
};