{"record":{"id":"14838d235ff23328","repo":"DIYgod/RSSHub","slug":"html-14838d","errorCode":null,"errorMessage":"无法找到HTML内容","messagePattern":"无法找到HTML内容","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/routes/zhizhuan100/report.ts","lineNumber":40,"sourceCode":"\nasync function handler() {\n    const urlData = await ofetch('https://www.zhizhuan100.com.cn/analysis');\n\n    const $ = load(urlData);\n\n    const bodyJsUrl: string | undefined = $('script[src*=\"Body.js\"]').attr('src');\n\n    if (!bodyJsUrl) {\n        throw new Error('无法找到 Body.js 脚本文件');\n    }\n\n    const responseData = await ofetch(bodyJsUrl, {\n        parseResponse: (txt) => txt,\n    });\n\n    const htmlMatch = responseData.match(/document\\.write\\('(.*)'\\);/s);\n    if (!htmlMatch) {\n        throw new Error('无法找到HTML内容');\n    }\n\n    const htmlContent = JSON.parse(`\"${htmlMatch[1]}\"`);\n    const $content = load(htmlContent);\n\n    const listItems = $content('.w-list-item');\n\n    const items = listItems\n        .toArray()\n        .map((item) => {\n            const $item = $content(item);\n            const titleElement = $item.find('.w-list-title');\n            const dateElement = $item.find('.w-list-date');\n            const linkElement = $item.find('.w-list-link');\n            const imgElement = $item.find('.w-listpic-in');\n\n            const title = titleElement.text() || '';\n            const dateText = dateElement.text() || '';","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/zhizhuan100/report.ts#L22-L58","documentation":"Thrown by the zhizhuan100 report route after it downloads the `Body.js` script: it expects the script body to contain a `document.write('...');` call and regex-extracts the inner HTML string. If the regex doesn't match (the script no longer uses `document.write`, or its format changed), the route cannot recover the report HTML and aborts.","triggerScenarios":"The `Body.js` script stops using `document.write('...')` — e.g. the site switches to `document.writeln`, template literals, DOM APIs (`innerHTML =`), or wraps the HTML differently — so the `/document\\.write\\('(.*)'\\);/s` regex no longer matches.","commonSituations":"A site rebuild changes how the report HTML is injected; the script now builds HTML from a JS variable/array; the HTML is split across multiple statements; minification alters the quoting/format. The mismatch makes `htmlMatch` null.","solutions":["Fetch the current `Body.js` content, inspect how it emits HTML, and update the extraction regex/logic to match the new pattern (e.g. `innerHTML\\s*=\\s*['\"](.+?)['\"]`).","Prefer hitting the site's data API directly (find it in the Network tab) rather than parsing injected HTML out of a script, which is fragile.","If `document.write` is still used but multi-line/quoting changed, loosen the regex flags or unescape sequence accordingly."],"exampleFix":"// before\nconst htmlMatch = responseData.match(/document\\.write\\('(.*)'\\);/s);\n// after — match the new innerHTML assignment\nconst htmlMatch = responseData.match(/innerHTML\\s*=\\s*\"([\\s\\S]+?)\";/);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let htmlMatch = responseData.match(/document\\.write\\('(.*)'\\);/s);\nif (!htmlMatch) {\n    // try alternative injection patterns the site may have switched to\n    htmlMatch = responseData.match(/innerHTML\\s*=\\s*\"([\\s\\S]+?)\";/)\n        ?? responseData.match(/document\\.writeln\\(\"([\\s\\S]+?)\"\\);/);\n}\nif (!htmlMatch) {\n    throw new Error('无法找到HTML内容');\n}","preventionTips":["Don't rely on a single regex against a third-party script — keep fallback patterns and log which one matched.","Migrate to the site's JSON API (visible in the Network tab) to remove script-scraping entirely.","Snapshot-test the Body.js extraction so a format change is caught before deploy."],"tags":["zhizhuan100","scraping","regex","site-change"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}