{"record":{"id":"b879700a34d9acf6","repo":"xpzouying/xiaohongshu-mcp","slug":"error-b87970","errorCode":null,"errorMessage":"无法获取初始状态数据","messagePattern":"无法获取初始状态数据","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/feed_detail.go","lineNumber":964,"sourceCode":"\n\t// 使用retry-go来处理可能的DOM查询失败\n\terr := retry.Do(\n\t\tfunc() error {\n\t\t\tevalResult := page.MustEval(`() => {\n\t\t\t\tif (window.__INITIAL_STATE__ &&\n\t\t\t\t\twindow.__INITIAL_STATE__.note &&\n\t\t\t\t\twindow.__INITIAL_STATE__.note.noteDetailMap) {\n\t\t\t\t\tconst noteDetailMap = window.__INITIAL_STATE__.note.noteDetailMap;\n\t\t\t\t\treturn JSON.stringify(noteDetailMap);\n\t\t\t\t}\n\t\t\t\treturn \"\";\n\t\t\t}`).String()\n\n\t\t\tif evalResult != \"\" {\n\t\t\t\tresult = evalResult\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"无法获取初始状态数据\")\n\t\t},\n\t\tretry.Attempts(3),\n\t\tretry.Delay(200*time.Millisecond),\n\t\tretry.MaxJitter(300*time.Millisecond),\n\t\tretry.OnRetry(func(n uint, err error) {\n\t\t\tlogrus.Debugf(\"提取Feed详情重试 #%d: %v\", n, err)\n\t\t}),\n\t)\n\n\tif err != nil {\n\t\tlogrus.Errorf(\"提取Feed详情失败: %v\", err)\n\t\treturn nil, fmt.Errorf(\"提取Feed详情失败: %w\", err)\n\t}\n\n\tif result == \"\" {\n\t\treturn nil, errors.ErrNoFeedDetail\n\t}\n","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/feed_detail.go#L946-L982","documentation":"extractFeedDetail evaluates an in-page JS snippet to pull the initial-state JSON (window __INITIAL_STATE__). If the evaluation returns an empty string, it throws '无法获取初始状态数据'; the retry wrapper retries 3 times with backoff before giving up.","triggerScenarios":"Page loaded but __INITIAL_STATE__ is missing/empty — e.g. redirected to a login/verification page, SPA not hydrated yet, or a structurally changed page after a xiaohongshu frontend update.","commonSituations":"Anti-bot redirect to verify page; slow network where rod captured the DOM before state was injected; xiaohongshu changed the global state variable name.","solutions":["Increase wait/delay before extraction (wait for the state element or network idle)","Verify the session isn't being redirected to a login/CAPTCHA page","Update the JS extraction snippet if xiaohongshu renamed __INITIAL_STATE__"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var detail *FeedDetailResponse\nerr := retry.Do(\n    func() error { var e error; detail, e = client.GetFeedDetailWithConfig(ctx, id, cfg); return e },\n    retry.Attempts(3), retry.DelayType(retry.BackOffDelay),\n)","preventionTips":["Ensure the browser page reaches network-idle / hydrated state before detail calls","Use valid authenticated sessions to avoid verification redirects","Watch for xiaohongshu frontend releases that rename __INITIAL_STATE__"],"tags":["xiaohongshu","scraping","dom-extraction"],"backgroundTag":"initial-state-missing","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}