{"record":{"id":"21a174a1827f1d5c","repo":"fish2018/pansou","slug":"d-21a174","errorCode":null,"errorMessage":"搜索响应状态码异常: %d","messagePattern":"搜索响应状态码异常: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/leijing/leijing.go","lineNumber":137,"sourceCode":"\n// searchImpl 实际的搜索实现\nfunc (p *LeijingPlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {\n\tsearchURL := fmt.Sprintf(\"%s%s?keyword=%s\", BaseURL, SearchPath, url.QueryEscape(keyword))\n\t\n\tif p.debugMode {\n\t\tlog.Printf(\"[Leijing] 开始搜索: %s\", keyword)\n\t\tlog.Printf(\"[Leijing] 搜索URL: %s\", searchURL)\n\t}\n\t\n\t// 发送搜索请求\n\tresp, err := p.doRequest(client, searchURL, BaseURL)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"发送搜索请求失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"搜索响应状态码异常: %d\", resp.StatusCode)\n\t}\n\t\n\t// 处理响应体（可能是gzip压缩的）\n\treader, err := p.getResponseReader(resp)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t\n\t// 解析HTML\n\tdoc, err := goquery.NewDocumentFromReader(reader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"解析HTML失败: %w\", err)\n\t}\n\t\n\t// 提取搜索结果\n\tresults := p.extractSearchResults(doc, keyword)\n\t\n\tif p.debugMode {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/leijing/leijing.go#L119-L155","documentation":"searchImpl in the leijing plugin checks the HTTP status after the search request and rejects anything other than 200 OK. This means the server responded but indicated the request was not successful (redirect to captcha, 403 anti-bot, 404 after site restructure, 5xx outage).","triggerScenarios":"doRequest succeeded but resp.StatusCode != http.StatusOK for the search URL — e.g. the site returns 403 for bot-like traffic, 301/302 to a login/captcha page (if redirects were not followed), or 503 during maintenance.","commonSituations":"Anti-bot protection (Cloudflare/WAF) challenging the crawler; site restructured and the search path now 404s; rate limiting returning 429; CDN serving 5xx errors.","solutions":["Log the status code and body snippet to identify what the server actually returned","Add anti-bot headers (realistic User-Agent, Referer, Cookie) to pass WAF checks","Handle 429 with backoff/retry; handle redirects by updating the URL constant","Verify the search URL path still exists on the site and update if restructured","Route through a proxy or reduce request rate if the site throttles by IP"],"exampleFix":"// before\nreturn nil, fmt.Errorf(\"搜索响应状态码异常: %d\", resp.StatusCode)\n// after\nbody, _ := io.ReadAll(io.LimitReader(resp.Body, 512))\nreturn nil, fmt.Errorf(\"搜索响应状态码异常: %d, body: %s\", resp.StatusCode, body)","handlingStrategy":"validation","validationCode":"// pre-flight: confirm the search endpoint still returns 200\nresp, err := client.Head(searchURL)\nif err != nil || resp.StatusCode != http.StatusOK {\n    log.Printf(\"leijing endpoint unhealthy: status=%v err=%v\", resp, err)\n}","typeGuard":null,"tryCatchPattern":"results, err := plugin.Search(ctx, keyword)\nif err != nil {\n    var statusErr interface{ Error() string }\n    if strings.Contains(err.Error(), \"搜索响应状态码异常\") {\n        // extract status, back off for 429/5xx, or switch mirror\n        return alternateSearch(keyword)\n    }\n    return err\n}","preventionTips":["Send full browser-like headers to avoid WAF/anti-bot 403s","Respect rate limits; back off on 429 instead of hammering","Monitor for site restructures and update the search path promptly","Handle redirects explicitly and update constants when domains move","Log response bodies on unexpected statuses for faster triage"],"tags":["go","http","status-code","scraping"],"backgroundTag":"http-non-200-response","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}