DIYgod/RSSHub · error
无法找到HTML内容
Error message
无法找到HTML内容
What it means
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.
Source
Thrown at lib/routes/zhizhuan100/report.ts:40
async function handler() {
const urlData = await ofetch('https://www.zhizhuan100.com.cn/analysis');
const $ = load(urlData);
const bodyJsUrl: string | undefined = $('script[src*="Body.js"]').attr('src');
if (!bodyJsUrl) {
throw new Error('无法找到 Body.js 脚本文件');
}
const responseData = await ofetch(bodyJsUrl, {
parseResponse: (txt) => txt,
});
const htmlMatch = responseData.match(/document\.write\('(.*)'\);/s);
if (!htmlMatch) {
throw new Error('无法找到HTML内容');
}
const htmlContent = JSON.parse(`"${htmlMatch[1]}"`);
const $content = load(htmlContent);
const listItems = $content('.w-list-item');
const items = listItems
.toArray()
.map((item) => {
const $item = $content(item);
const titleElement = $item.find('.w-list-title');
const dateElement = $item.find('.w-list-date');
const linkElement = $item.find('.w-list-link');
const imgElement = $item.find('.w-listpic-in');
const title = titleElement.text() || '';
const dateText = dateElement.text() || '';View on GitHub (pinned to bed535e087)
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.
Example fix
// before
const htmlMatch = responseData.match(/document\.write\('(.*)'\);/s);
// after — match the new innerHTML assignment
const htmlMatch = responseData.match(/innerHTML\s*=\s*"([\s\S]+?)";/); Defensive patterns
Strategy: fallback
Try / catch
let htmlMatch = responseData.match(/document\.write\('(.*)'\);/s);
if (!htmlMatch) {
// try alternative injection patterns the site may have switched to
htmlMatch = responseData.match(/innerHTML\s*=\s*"([\s\S]+?)";/)
?? responseData.match(/document\.writeln\("([\s\S]+?)"\);/);
}
if (!htmlMatch) {
throw new Error('无法找到HTML内容');
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 无法找到 Body.js 脚本文件
- 无法获取最新的 year 和 issue
- Cannot find n-token
- WapHomeRenderData 数据未找到
- Cannot extract __INITIAL_SSR_STATE__
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/14838d235ff23328.
Report an issue: GitHub.