{"record":{"id":"778b843a84d3e906","repo":"DIYgod/RSSHub","slug":"failed-to-find-next-data-script-tag-in-page-u","errorCode":null,"errorMessage":"Failed to find __NEXT_DATA__ script tag in page${url ? `: ${url}` : ''}","messagePattern":"Failed to find __NEXT_DATA__ script tag in page(.+?)` : ''\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/hupu/utils.ts","lineNumber":12,"sourceCode":"import { load } from 'cheerio';\n\nimport type { DataItem } from '@/types';\nimport cache from '@/utils/cache';\nimport got from '@/utils/got';\nimport { parseDate, parseRelativeDate } from '@/utils/parse-date';\nimport timezone from '@/utils/timezone';\n\nexport function extractNextData<T = unknown>(html: string, url?: string): T {\n    const scriptMatch = html.match(/<script id=\"__NEXT_DATA__\" type=\"application\\/json\">(.*?)<\\/script>/);\n    if (!scriptMatch || !scriptMatch[1]) {\n        throw new Error(`Failed to find __NEXT_DATA__ script tag in page${url ? `: ${url}` : ''}`);\n    }\n\n    try {\n        return JSON.parse(scriptMatch[1]) as T;\n    } catch (error) {\n        throw new Error(`Failed to parse __NEXT_DATA__ JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });\n    }\n}\n\ninterface ThreadNextData {\n    props: {\n        pageProps: {\n            threadData: {\n                data: {\n                    moduleConfigList: {\n                        content: {\n                            moduleContent: {\n                                content: string;","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/hupu/utils.ts#L1-L30","documentation":"Thrown by the `extractNextData` utility (shared across Hupu routes) when the provided HTML string does not contain a `<script id=\"__NEXT_DATA__\" type=\"application/json\">` tag with JSON content. The function uses a regex to locate this tag. If the upstream Hupu page changed its structure, served a blocked/challenge page, or returned an error page without the Next.js data script, the regex fails to match.","triggerScenarios":"The Hupu page served to RSSHub does not contain the expected `__NEXT_DATA__` script tag — this happens when the site is under maintenance, returns a CAPTCHA/anti-bot challenge, changes its SSR framework, or the specific page (e.g. a deleted thread) returns a 404 error page without Next.js data.","commonSituations":"Hupu deploys anti-bot protection that serves a different HTML to server-side fetchers, a thread was deleted and the URL returns a custom 404, the site migrated away from Next.js, or the RSSHub instance's IP is rate-limited.","solutions":["Open the failing URL in a browser to see what HTML is actually returned.","If a CAPTCHA/anti-bot page is returned, consider using `config.trueUA` or adding Puppeteer-based fetching.","If a specific thread URL is dead, this is transient and the cache will eventually expire.","If the site migrated, update the parsing logic in `extractNextData` and its callers."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasNextDataScript(html: string): boolean {\n    return /<script id=\"__NEXT_DATA__\" type=\"application\\/json\">/.test(html);\n}","tryCatchPattern":"try {\n    const data = extractNextData<T>(html, url);\n    return data;\n} catch (err) {\n    // Log the HTML length and first N chars for diagnosis without surfacing to users\n    throw new Error(`Could not extract Next.js data from ${url}: ${err instanceof Error ? err.message : String(err)}`);\n}","preventionTips":["Monitor upstream site structure changes.","Use `config.trueUA` for realistic browser headers to avoid anti-bot challenge pages.","Cache successfully parsed pages to reduce re-fetch exposure.","Consider falling back to Puppeteer for pages that serve different HTML to server-side clients."],"tags":["upstream","parsing","schema-change","anti-bot","rsshub","bbs"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}