fix(route): sehuatang 403报错 (#15915)
* 1. 修复sehuatang 403 * 修复sehuatang主页 403 * 过滤不必要的请求
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import logger from '@/utils/logger';
|
||||
import puppeteer from '@/utils/puppeteer';
|
||||
|
||||
const host = 'https://www.sehuatang.net/';
|
||||
|
||||
@@ -41,6 +42,9 @@ export const route: Route = {
|
||||
path: ['/bt/:subforumid?', '/picture/:subforumid', '/:subforumid?/:type?', '/:subforumid?', ''],
|
||||
name: 'Unknown',
|
||||
maintainers: ['qiwihui', 'junfengP', 'nczitzk'],
|
||||
features: {
|
||||
requirePuppeteer: true,
|
||||
},
|
||||
handler,
|
||||
description: `**原创 BT 电影**
|
||||
|
||||
@@ -61,16 +65,24 @@ async function handler(ctx) {
|
||||
const type = ctx.req.param('type');
|
||||
const typefilter = type ? `&filter=typeid&typeid=${type}` : '';
|
||||
const link = `${host}forum.php?mod=forumdisplay&orderby=dateline&fid=${subformId}${typefilter}`;
|
||||
const headers = {
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||
Cookie: '_safe=vqd37pjm4p5uodq339yzk6b7jdt6oich',
|
||||
};
|
||||
|
||||
const response = await got(link, {
|
||||
headers,
|
||||
const browser = await puppeteer();
|
||||
const page = await browser.newPage();
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', (request) => {
|
||||
request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort();
|
||||
});
|
||||
const $ = load(response.data);
|
||||
logger.http(`Requesting ${link}`);
|
||||
await page.goto(link, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
await page.waitForSelector('a.enter-btn', { visible: true });
|
||||
|
||||
await Promise.all([page.click('a.enter-btn'), page.waitForNavigation({ waitUntil: 'domcontentloaded' })]);
|
||||
const response = await page.content();
|
||||
page.close();
|
||||
|
||||
const $ = load(response);
|
||||
|
||||
const list = $('#threadlisttableid tbody[id^=normalthread]')
|
||||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25)
|
||||
@@ -89,11 +101,19 @@ async function handler(ctx) {
|
||||
const out = await Promise.all(
|
||||
list.map((info) =>
|
||||
cache.tryGet(info.link, async () => {
|
||||
const response = await got(info.link, {
|
||||
headers,
|
||||
const page = await browser.newPage();
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', (request) => {
|
||||
request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort();
|
||||
});
|
||||
|
||||
const $ = load(response.data);
|
||||
await page.goto(info.link, {
|
||||
// 指定页面等待载入的时间
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
const response = await page.content();
|
||||
|
||||
const $ = load(response);
|
||||
const postMessage = $("td[id^='postmessage']").slice(0, 1);
|
||||
const images = $(postMessage).find('img');
|
||||
for (const image of images) {
|
||||
@@ -136,7 +156,7 @@ async function handler(ctx) {
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await browser.close();
|
||||
return {
|
||||
title: `色花堂 - ${$('#pt > div:nth-child(1) > a:last-child').text()}`,
|
||||
link,
|
||||
|
||||
Reference in New Issue
Block a user