fish2018/pansou · error

未找到磁力链接输入框

Error message

未找到磁力链接输入框

What it means

After parsing the detail page, fetchMagnetLink looks for input#input-magnet via doc.Find. If no element matches, the page did not contain the expected magnet-link input, so this error is thrown. It means the DOM structure differs from what the plugin expects — the site changed, was replaced by an error/challenge page, or the URL does not actually point at a resource detail page.

Solutions

  1. Dump and inspect the HTML body (log first N chars) when this error occurs to see what the page actually contains.
  2. Update the selector in code to match the site's current DOM if the template changed.
  3. Detect challenge/error pages (e.g. body contains 'Just a moment' or title mismatch) and retry or rotate UA/cookies instead of parsing them.
  4. Check whether the magnet value is rendered by JavaScript; if so, find the JSON/API endpoint the page calls and use that instead of scraping HTML.
  5. Fall back to searching alternative magnet selectors or link elements containing 'magnet:' prefixes in the page.

Example fix

// before
magnetInput := doc.Find("input#input-magnet")
if magnetInput.Length() == 0 {
    return "", fmt.Errorf("未找到磁力链接输入框")
}
// after
magnetInput := doc.Find("input#input-magnet")
if magnetInput.Length() == 0 {
    // fallback: scan for a raw magnet link anywhere in the page
    var found string
    doc.Find("a[href^='magnet:']").Each(func(_ int, s *goquery.Selection) {
        if found == "" {
            found, _ = s.Attr("href")
        }
    })
    if found == "" {
        return "", fmt.Errorf("未找到磁力链接输入框")
    }
    return found, nil
}
Defensive patterns

Strategy: fallback

Validate before calling

// after parsing, verify expected structure before extracting
if doc.Find("input#input-magnet").Length() == 0 && doc.Find("a[href^='magnet:']").Length() == 0 {
    return fmt.Errorf("page lacks magnet element (challenge or template change?)")
}

Try / catch

magnet, err := p.fetchMagnetLink(client, detailURL)
if err != nil {
    log.Printf("no magnet found on %s: %v", detailURL, err)
    return "" // keep result without magnet
}

Prevention

When it happens

Trigger: The parsed HTML has no input element with id "input-magnet": a 200-status anti-bot or JS-rendered challenge page, a site redesign renaming the id, a soft-error page returned with 200, or the magnet being loaded dynamically via JavaScript so it never appears in the raw HTML.

Common situations: The wuji site updating its template so the input id changes; Cloudflare or a JS challenge served with status 200; the magnet input being populated client-side by JS instead of server-side; hitting a generic 'not found' page that still returns 200.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at plugin/wuji/wuji.go:341

		return "", fmt.Errorf("详情页返回状态码: %d", resp.StatusCode)
	}
	
	// 读取响应体内容
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return "", fmt.Errorf("读取详情页响应失败: %w", err)
	}
	
	// 解析HTML
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(body)))
	if err != nil {
		return "", fmt.Errorf("详情页HTML解析失败: %w", err)
	}
	
	// 提取磁力链接
	magnetInput := doc.Find("input#input-magnet")
	if magnetInput.Length() == 0 {
		return "", fmt.Errorf("未找到磁力链接输入框")
	}
	
	magnetLink, exists := magnetInput.Attr("value")
	if !exists || magnetLink == "" {
		return "", fmt.Errorf("磁力链接为空")
	}
	
	// 存入缓存
	magnetCache.Store(detailURL, magnetCacheEntry{
		MagnetLink: magnetLink,
		Timestamp:  time.Now(),
	})
	
	return magnetLink, nil
}

// cleanTitle 清理标题中的广告内容
func (p *WujiPlugin) cleanTitle(title string) string {

View on GitHub (pinned to beaa561337)