Documentation
¶
Index ¶
- type Config
- type EmptyContentError
- type Engine
- func (e *Engine) CleanFiles() (int, error)
- func (e *Engine) Close() error
- func (e *Engine) Fetch(ctx context.Context, url string) (*FetchResult, error)
- func (e *Engine) FetchWithOpts(ctx context.Context, url string, opts FetchOptions) (*FetchResult, error)
- func (e *Engine) ParsePDFBytes(ctx context.Context, data []byte, name string) (*PDFResult, error)
- func (e *Engine) ParsePDFFile(ctx context.Context, filePath string) (*PDFResult, error)
- func (e *Engine) ParsePDFURL(ctx context.Context, url string) (*PDFResult, error)
- type FetchOptions
- type FetchResult
- type NotFoundError
- type PDFParseError
- type PDFResult
- type SSRFError
- type TimeoutError
- type UnsupportedContentTypeError
- type WAFError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ── HTTP ──
UserAgent string // 默认 Chrome 124 UA
ExtraHeaders map[string]string // 额外请求头
Timeout time.Duration // 单次请求超时,默认 15s
MaxRedirects int // 最大重定向次数,默认 5
// ── 代理 ──
ProxyURL string // HTTP 代理地址,如 "http://user:pass@host:port"
UseSystemProxy bool // 自动使用系统代理(读取 HTTP_PROXY/HTTPS_PROXY 环境变量)
// ── 安全 ──
BlockPrivateIP bool // SSRF 防护,默认 true
MaxURLLength int // 默认 2048
MaxBodyBytes int64 // 下载上限,默认 5MB
// ── 内容输出 ──
MaxInlineLines int // Markdown 超过此行数则写文件,默认 100
MaxInlineChars int // Markdown 超过此字符数则写文件,默认 0(不启用)
MaxContentLength int // 输出给 LLM 的内容上限,默认 100000(100KB)
FileOutputDir string // 文件输出目录,默认 os.TempDir()/webfetch/
FileTTL time.Duration // 文件保留时间,默认 24h
// ── 反爬 ──
FastFailWAF bool // 遇 WAF 立即失败,默认 true
MaxRetries int // 最大重试次数,默认 3
// ── PDF ──
PDFMaxPages int // 最大解析页数,默认 200
PDFHeuristic bool // 是否启用启发式结构化,默认 true
}
Config 引擎配置
type EmptyContentError ¶
EmptyContentError 表示页面返回了 HTTP 200 但内容为空或过少 通常是反爬机制返回的空壳页面(JS 渲染、Token 验证等)
func (*EmptyContentError) Error ¶
func (e *EmptyContentError) Error() string
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 抓取引擎
func (*Engine) FetchWithOpts ¶
func (e *Engine) FetchWithOpts(ctx context.Context, url string, opts FetchOptions) (*FetchResult, error)
FetchWithOpts 带选项的抓取
func (*Engine) ParsePDFBytes ¶
ParsePDFBytes 解析 PDF 字节流
func (*Engine) ParsePDFFile ¶
ParsePDFFile 解析本地 PDF 文件
type FetchOptions ¶
FetchOptions 抓取选项(FetchWithOpts 使用)
type FetchResult ¶
type FetchResult struct {
URL string `json:"url"`
FinalURL string `json:"final_url"`
Title string `json:"title"`
StatusCode int `json:"status_code"`
ContentType string `json:"content_type"`
Method string `json:"method"` // "native-http" | "headless" | "direct"
FetchedAt time.Time `json:"fetched_at"`
Elapsed time.Duration `json:"elapsed"`
// 输出二选一
Mode string `json:"mode"` // "inline" | "saved_to_file"
Markdown string `json:"markdown,omitempty"`
FilePath string `json:"file_path,omitempty"`
// saved_to_file 时的元数据
TotalLines int `json:"total_lines,omitempty"`
TotalChars int `json:"total_chars,omitempty"`
Summary string `json:"summary,omitempty"`
AgentHint string `json:"agent_hint,omitempty"`
Error string `json:"error,omitempty"`
ErrorType string `json:"error_type,omitempty"`
}
FetchResult 网页抓取结果
type NotFoundError ¶
NotFoundError 表示 URL 返回 404
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type PDFParseError ¶
PDFParseError 表示 PDF 解析失败
func (*PDFParseError) Error ¶
func (e *PDFParseError) Error() string
type PDFResult ¶
type PDFResult struct {
SourcePath string `json:"source_path"`
Title string `json:"title"`
PageCount int `json:"page_count"`
Method string `json:"method"` // "go-fitz"
Mode string `json:"mode"`
Markdown string `json:"markdown,omitempty"`
FilePath string `json:"file_path,omitempty"`
TotalLines int `json:"total_lines,omitempty"`
TotalChars int `json:"total_chars,omitempty"`
Summary string `json:"summary,omitempty"`
AgentHint string `json:"agent_hint,omitempty"`
Error string `json:"error,omitempty"`
ErrorType string `json:"error_type,omitempty"`
}
PDFResult PDF 解析结果
type TimeoutError ¶
type TimeoutError struct {
URL string
}
TimeoutError 表示请求超时
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type UnsupportedContentTypeError ¶
type UnsupportedContentTypeError struct {
ContentType string
}
UnsupportedContentTypeError 表示不支持的 Content-Type
func (*UnsupportedContentTypeError) Error ¶
func (e *UnsupportedContentTypeError) Error() string
Click to show internal directories.
Click to hide internal directories.