fish2018/pansou · error

无法从Location中提取searchid

Error message

无法从Location中提取searchid: %s

What it means

In getSearchID, after receiving a redirect the plugin parses the Location header with extractSearchIDFromLocation. If the URL in Location does not contain a parseable searchid, this error is thrown with the offending URL. It indicates the redirect target's format no longer matches what the parser expects.

Solutions

  1. Log the full Location URL and compare with extractSearchIDFromLocation's expected format; update the parser to the new URL shape.
  2. Confirm the request is authenticated/has valid cookies so the redirect goes to results, not a login page.
  3. Check if the upstream renamed the searchid parameter and update the extraction accordingly.
  4. Add a fallback that follows the redirect and scrapes the searchid from the response body if it is no longer in the URL.
Defensive patterns

Strategy: fallback

Try / catch

res, err := client.SearchWithResult(ctx, keyword)
if err != nil && strings.Contains(err.Error(), "无法从Location中提取searchid") {
    // parser out of date with upstream URL shape: try alternative plugin or re-fetch
    res, err = fallbackSearch(ctx, keyword)
}

Prevention

When it happens

Trigger: SearchWithResult triggers a request whose 302 Location header parses to a URL lacking the searchid parameter/path segment — e.g. the upstream changed the redirect URL structure or redirected to a login/home page.

Common situations: Upstream site updated its search flow so the searchid moved or was renamed; redirect goes to an error/login page instead of the results page; query-string encoding changed so the regex/parse fails.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/016d91e91a27a8b6. Report an issue: GitHub.

Appendix: source

Thrown at plugin/clxiong/clxiong.go:169

		return "", lastErr
	}
	defer resp.Body.Close()

	// 检查重定向响应
	if resp.StatusCode != 302 && resp.StatusCode != 301 {
		return "", fmt.Errorf("期望302重定向,但得到状态码: %d", resp.StatusCode)
	}

	// 从Location头部提取searchid
	location := resp.Header.Get("Location")
	if location == "" {
		return "", fmt.Errorf("重定向响应中没有Location头部")
	}

	// 解析searchid
	searchID := p.extractSearchIDFromLocation(location)
	if searchID == "" {
		return "", fmt.Errorf("无法从Location中提取searchid: %s", location)
	}

	if p.debugMode {
		log.Printf("[CLXIONG] 获取到searchid: %s", searchID)
	}

	return searchID, nil
}

// extractSearchIDFromLocation 从Location头部提取searchid
func (p *ClxiongPlugin) extractSearchIDFromLocation(location string) string {
	// location格式: "result/?searchid=7549"
	re := regexp.MustCompile(`searchid=(\d+)`)
	matches := re.FindStringSubmatch(location)
	if len(matches) > 1 {
		return matches[1]
	}
	return ""

View on GitHub (pinned to beaa561337)