fish2018/pansou · error
首页未找到入口脚本
Error message
首页未找到入口脚本
What it means
discoverServerFunctionID fetches the Xiaokupan site homepage and regex-extracts the JS entry-bundle path via indexAssetPattern. If the pattern does not match anything in the HTML, it returns this error instead of continuing, because the next step (fetching the entry script) cannot proceed without a path. It is thrown when the site's homepage markup no longer matches the expected script-tag shape.
Solutions
- Fetch the homepage manually (curl with a browser User-Agent) and compare the actual script tag against indexAssetPattern; update the regex to match the new markup.
- Check whether the request was served by a WAF/anti-bot layer (inspect homeBody content) and add appropriate headers/cookies to req.
- Pin/upgrade the plugin to a version that matches the current site layout.
- Log homeBody on this failure path to diagnose which page shape was actually received.
Example fix
// before
assetPath := string(indexAssetPattern.Find(homeBody))
if assetPath == "" {
return "", fmt.Errorf("首页未找到入口脚本")
}
// after
assetPath := string(indexAssetPattern.Find(homeBody))
if assetPath == "" {
return "", fmt.Errorf("首页未找到入口脚本 (body %d bytes, first 200: %.200q)", len(homeBody), homeBody)
} Defensive patterns
Strategy: fallback
Validate before calling
resp, _ := http.Get(baseURL)
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if !indexAssetPattern.Match(body) {
// site layout changed or blocked; skip plugin or alert
} Type guard
func hasEntryAsset(homeBody []byte) bool { return len(indexAssetPattern.Find(homeBody)) > 0 } Try / catch
funcID, err := discoverServerFunctionID(ctx, req)
if err != nil {
if strings.Contains(err.Error(), "首页未找到入口脚本") {
log.Printf("xiaokupan layout changed: %v", err)
return nil, errSkipPlugin
}
return nil, err
} Prevention
- Alert on this error so site-layout changes are noticed quickly.
- Fetch the homepage with realistic browser headers to avoid WAF challenge pages.
- Keep the asset regex tolerant (multiple tag shapes) rather than exact-match only.
When it happens
Trigger: indexAssetPattern.Find(homeBody) returns an empty match: the homepage HTML contains no <script src=...> (or equivalent) tag matching the pattern — e.g. the site returned a challenge/captcha page, an error page, a redirect stub, or changed its bundler/template output.
Common situations: The upstream site redesigned its frontend or changed its asset bundling; a CDN/WAF serves a bot-check page instead of the real homepage; network middleware intercepts the request; the plugin was written against an older site layout.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/1c1fb1420a30eeec.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/xiaokupan/xiaokupan.go:238
func (p *XiaokupanPlugin) discoverServerFunctionID(client *http.Client) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
homeURL := strings.TrimRight(p.baseURL, "/") + "/"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, homeURL, nil)
if err != nil {
return "", err
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36")
req.Header.Set("Accept", "text/html,application/xhtml+xml")
homeBody, err := doLimitedRequest(client, req, maxDiscoveryBodySize)
if err != nil {
return "", fmt.Errorf("读取首页失败: %w", err)
}
assetPath := string(indexAssetPattern.Find(homeBody))
if assetPath == "" {
return "", fmt.Errorf("首页未找到入口脚本")
}
assetReq, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(p.baseURL, "/")+assetPath, nil)
if err != nil {
return "", err
}
assetReq.Header.Set("User-Agent", req.Header.Get("User-Agent"))
assetReq.Header.Set("Referer", homeURL)
assetBody, err := doLimitedRequest(client, assetReq, maxDiscoveryBodySize)
if err != nil {
return "", fmt.Errorf("读取入口脚本失败: %w", err)
}
routeIndex := strings.Index(string(assetBody), "/s/$query")
if routeIndex < 0 {
return "", fmt.Errorf("入口脚本未找到搜索路由")
}
windowStart := max(0, routeIndex-2048)
hashes := hashPattern.FindAll(assetBody[windowStart:routeIndex], -1)View on GitHub (pinned to beaa561337)