{"record":{"id":"e8e37fa59a60f378","repo":"DIYgod/RSSHub","slug":"discuz-discuz-x-discuz","errorCode":null,"errorMessage":"无法检测 Discuz 版本，请在路由中指定版本参数，如 /discuz/x/ 或 /discuz/7/","messagePattern":"无法检测 Discuz 版本，请在路由中指定版本参数，如 /discuz/x/ 或 /discuz/7/","errorType":"exception","errorClass":"InvalidParameterError","httpStatus":null,"severity":"warning","filePath":"lib/routes/discuz/discuz.ts","lineNumber":125,"sourceCode":"\n    const header = {\n        Cookie: cookie,\n    };\n\n    const { response, responseData } = await fetchWithAntiBot(link, header);\n\n    // 若没有指定编码，则默认utf-8\n    const contentType = response.headers['content-type'] || '';\n    let $ = load(iconv.decode(responseData, 'utf-8'));\n    const charset = contentType.match(/charset=([^;]*)/)?.[1] ?? $('meta[charset]').attr('charset') ?? $('meta[http-equiv=\"Content-Type\"]').attr('content')?.split('charset=', 2)?.[1];\n    if (charset?.toLowerCase() !== 'utf-8') {\n        $ = load(iconv.decode(responseData, charset ?? 'utf-8'));\n    }\n\n    const version = ver ? `DISCUZ! ${ver}` : $('head > meta[name=generator]').attr('content');\n\n    if (!version) {\n        throw new InvalidParameterError('无法检测 Discuz 版本，请在路由中指定版本参数，如 /discuz/x/ 或 /discuz/7/');\n    }\n\n    let items;\n    if (version.toUpperCase().startsWith('DISCUZ! 7')) {\n        // discuz 7.x 系列\n        // 支持全文抓取，限制抓取页面5个\n        const list = $('tbody[id^=\"normalthread\"] > tr')\n            .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 5)\n            .toArray()\n            .map((item): DataItem => {\n                const $item = $(item);\n                const a = $item.find('span[id^=thread] a');\n                return {\n                    title: a.text().trim(),\n                    link: fixUrl(a.attr('href'), link),\n                    pubDate: $item.find('td.author em').length ? parseDate($item.find('td.author em').text().trim()) : undefined,\n                    author: $item.find('td.author cite a').text().trim(),\n                };","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/discuz/discuz.ts#L107-L143","documentation":"The Discuz route needs to know the forum software version (7.x or X/x) to apply the correct scraping selectors. It first checks the ver route parameter; if absent, it falls back to detecting the version from the HTML meta[name=generator] tag. If neither source yields a version string, InvalidParameterError instructs the user to specify the version explicitly in the route.","triggerScenarios":"The ver parameter is not provided (undefined), and $('head > meta[name=generator]').attr('content') returns undefined — the forum's HTML does not include a generator meta tag. This happens with customized or stripped-down Discuz installations that remove the generator meta tag, or when the page returned is not actually a Discuz forum.","commonSituations":"A Discuz forum has been customized to remove the meta[name=generator] tag for security/fingerprinting reasons; the link parameter points to a non-Discuz page (e.g., a portal, WordPress, or error page); the forum uses a heavily modified template; the URL is correct but the initial page is a redirect.","solutions":["Specify the version explicitly in the route path: use /discuz/x/<link> for Discuz X or /discuz/7/<link> for Discuz 7.x.","Check the forum's HTML source in a browser to find the generator meta tag or identify the version from page elements.","Verify the link parameter actually points to a Discuz forum (check for Discuz-specific CSS classes or scripts).","If the forum uses a newer or custom Discuz version, check which scraping selectors work and specify the closest version."],"exampleFix":"// Route usage — specify version explicitly\n// before: /discuz/https://example.com/forum.php\n// after:  /discuz/x/https://example.com/forum.php","handlingStrategy":"validation","validationCode":"const ver = ctx.req.param('ver')?.toUpperCase();\nconst version = ver ? `DISCUZ! ${ver}` : $('head > meta[name=generator]').attr('content');\nif (!version) {\n    throw new InvalidParameterError('Cannot detect Discuz version. Specify it in the route: /discuz/x/<link> for X or /discuz/7/<link> for 7.x');\n}\n// Also validate the version is supported\nif (!version.toUpperCase().startsWith('DISCUZ! 7') && !version.toUpperCase().startsWith('DISCUZ! X')) {\n    throw new InvalidParameterError(`Unsupported Discuz version: ${version}. Use /discuz/x/ or /discuz/7/`);\n}","typeGuard":"function isSupportedDiscuzVersion(version: string | undefined): boolean {\n    if (!version) return false;\n    const v = version.toUpperCase();\n    return v.startsWith('DISCUZ! 7') || v.startsWith('DISCUZ! X');\n}","tryCatchPattern":null,"preventionTips":["Always specify the version parameter in the route URL (e.g., /discuz/x/) to avoid relying on auto-detection.","Verify the URL points to an actual Discuz forum before using this route.","Check the forum's HTML source for the meta[name=generator] tag to determine the version.","Keep the route's version-specific selectors updated as Discuz releases new versions."],"tags":["discuz","validation","version-detection","html-scraping","invalid-parameter"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}