反爬增强
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { fetchDoubanWithVerification } from '@/lib/douban-anti-crawler';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -25,20 +26,10 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
// 请求豆瓣短评页面
|
||||
// 请求豆瓣短评页面(使用反爬验证)
|
||||
const url = `https://movie.douban.com/subject/${doubanId}/comments?start=${start}&limit=${limit}&status=P&sort=new_score`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
Accept:
|
||||
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||
Referer: 'https://movie.douban.com/',
|
||||
Cookie: 'bid=sadjkfhadskbfasdfdjh'
|
||||
},
|
||||
});
|
||||
const response = await fetchDoubanWithVerification(url);
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { fetchDoubanData } from '@/lib/douban';
|
||||
import { fetchDoubanWithVerification } from '@/lib/douban-anti-crawler';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -26,26 +27,10 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
// 请求豆瓣电影页面,使用和其他豆瓣API相同的请求头
|
||||
// 请求豆瓣电影页面(使用反爬验证)
|
||||
const url = `https://movie.douban.com/subject/${doubanId}/`;
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
||||
|
||||
const response = await fetch(url, {
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
|
||||
Referer: 'https://movie.douban.com/',
|
||||
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||
Origin: 'https://movie.douban.com',
|
||||
Cookie: 'bid=sadjkfhadskbfasdfdjh'
|
||||
},
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
const response = await fetchDoubanWithVerification(url);
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user