fish2018/pansou · error
解析搜索结果HTML失败
Error message
解析搜索结果HTML失败: %w
What it means
xb6v's searchImpl parses the search-results page HTML with goquery.NewDocumentFromReader. If goquery (via the underlying charset/HTML reader) fails to build a document, this error wraps the cause. In practice goquery rarely errors, so this usually reflects a reader-level failure such as a charset decoder error on malformed bytes.
Solutions
- Retry — corrupted transfer/encoding is usually transient.
- Inspect Content-Encoding and charset headers in debug logs; confirm the body decodes cleanly (curl --compressed | file -).
- Verify the mirror is serving intact pages; switch mirrors if the HTML is consistently malformed.
- Harden getResponseReader to validate the gzip stream and fall back to raw bytes before parsing.
Defensive patterns
Strategy: retry
Try / catch
results, err := pluginSearch(keyword)
if err != nil && strings.Contains(err.Error(), "解析搜索结果HTML失败") {
// corrupt transfer/encoding — retry once; then switch mirror
} Prevention
- Avoid proxies that alter or truncate response bodies.
- Verify mirror serves valid gzip and correct charset.
- Treat repeated parse failures as a signal to change mirrors.
When it happens
Trigger: goquery.NewDocumentFromReader(reader) returns an error while consuming the (possibly gzip-decompressed, charset-converted) response body of the results page — typically invalid byte sequences for the detected charset or a decompression error surfaced during the first read.
Common situations: Mirror serves content in a charset the transformer doesn't support or emits broken multi-byte sequences; the gzip stream is corrupt so the decoder errors mid-parse; a proxy injects content breaking the encoding.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/bb83774bc981bcd3.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/xb6v/xb6v.go:303
resp2, err := p.doRequest(client, "GET", resultURL, "", p.currentBase)
if err != nil {
return nil, fmt.Errorf("获取搜索结果失败: %w", err)
}
defer resp2.Body.Close()
if resp2.StatusCode != http.StatusOK {
return nil, fmt.Errorf("搜索结果响应状态码异常: %d", resp2.StatusCode)
}
// 解析搜索结果页面
reader, err := p.getResponseReader(resp2)
if err != nil {
return nil, err
}
doc, err := goquery.NewDocumentFromReader(reader)
if err != nil {
return nil, fmt.Errorf("解析搜索结果HTML失败: %w", err)
}
// 提取搜索结果(详情页链接和日期)
detailPages := p.extractDetailURLs(doc)
if p.debugMode {
log.Printf("[Xb6v] 找到 %d 个详情页链接", len(detailPages))
}
if len(detailPages) == 0 {
return nil, fmt.Errorf("未找到搜索结果")
}
// 限制结果数量
if len(detailPages) > MaxResults {
detailPages = detailPages[:MaxResults]
}
View on GitHub (pinned to beaa561337)