Skip to content

HTML ​

CyberGo html is a Go library for HTML content extraction and cleaning. It reads body text, titles, images, links, video, and audio from HTML bytes, with 30+ encoding detection and three output formats: plain text, Markdown, and JSON.

Features ​

  • Article Detection - Locates the page's main content and removes navigation, ads, and other noise
  • Reader Mode - ReadPage keeps the whole page as header/navigation/main/aside/footer sections and emits Markdown you can feed directly to an LLM
  • Structured Metadata / Extraction Confidence - Parses author, publication time, description, site name, and canonical URL; Confidence and ExtractionMethod report extraction quality and how the body text was produced (article / listing / body fallback)
  • Content Cleaning - Removes dangerous tags, event attributes, and dangerous protocols to reduce XSS risk
  • Resource Information Extraction - Produces structured titles, images, links, videos, and audio
  • Multi-Format Output - Plain text, Markdown, and JSON
  • Encoding Detection - UTF-8, GBK, Shift_JIS, Windows-1252, KOI8-R, and 30+ encodings
  • Batch Processing - Concurrent batch extraction sharing a single Processor instance
  • Link Extraction - Standalone link extraction API with type-based grouping
  • Audit System - Pluggable audit pipeline with multiple sinks and event filtering
  • Security Protection - Input size limits, depth limits, path traversal prevention, and panic recovery

Installation ​

bash
go get github.com/cybergodev/html

Quick Start ​

go
package main

import (
	"fmt"
	"log"

	"github.com/cybergodev/html"
)

func main() {
	data := []byte(`<html><head><title>Example</title></head>
        <body><h1>Title</h1><p>Body content</p></body></html>`)

	result, err := html.Extract(data)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.Title) // Output: Example
	fmt.Println(result.Text)
	// Output:
	// # Title
	//
	// Body content
}

Architecture Overview ​

The library is built around three core types:

text
                Config
                  │
                  ▼
             Processor ──→ Result
              │    │         │
              │    │         ├── Text / Title
              │    │         ├── Images / Videos / Audios
              │    │         ├── Links
              │    │         ├── Author / PublishedTime / Confidence
              │    │         └── WordCount / ReadingTime
              │    │
              │    ├── Cache
              │    ├── Statistics
              │    └── AuditLog
              │
              ├── Scorer (custom scoring ── extensible)
              └── AuditSink (audit output ── extensible)
TypeResponsibilityDescription
ConfigConfigurationControls all behavior; provides 4 presets
ProcessorEngineStateful processing engine managing cache, statistics, and audit
ResultResultStructured output containing text and all metadata

Package Functions vs Processor ​

Package FunctionsProcessor
Usagehtml.Extract(data)p, _ := html.New(cfg); p.Extract(data)
CacheNone (pooled instances have caching disabled)Yes, configurable TTL and capacity
StatisticsNoneYes, query hit rate and other metrics
AuditNoneYes, configurable audit pipeline
LifecycleNo management neededRequires defer p.Close()
Concurrency-safeYesYes

When to use each calling mode

  • One-time extraction (CLI tools, scripts) → Package functions
  • High-frequency server calls (web services, crawlers) → Processor
  • Audit or monitoring required → Processor

Learning Path ​

The recommended reading order, from first steps to advanced topics:

StagePageContent
Getting StartedQuick StartInstallation, basic usage, two calling modes
CoreContent ExtractionExtract family, Config, Result interpretation
ReaderReader ModeReadPage sectioned output, Render/RenderText, LLM input
MediaMedia ExtractionVideo, audio, and embedded content extraction
FormatsOutput FormatsMarkdown / JSON output, format configuration
LinksLink ExtractionLink extraction, grouping, resource discovery
EncodingEncoding DetectionAuto-detection, manual override, 30+ encodings
ConfigurationConfiguration GuideFour presets, six field categories, common combinations
ErrorsError HandlingFive error types, errors.Is/As, context cancellation
PerformanceCache & ReuseProcessor lifecycle, cache tuning
BatchBatch ProcessingConcurrent batch extraction, WorkerPool tuning
SecuritySecurity OverviewSecurity features, audit system, production checklist
AdvancedTesting & CustomCustom Scorer, ContentNode, test mode
ReferenceCheat SheetCommon API quick reference

Next Steps ​