SwiftSoup parses and mutates HTML on Apple platforms and Linux using DOM traversal, CSS selectors, and sanitization aligned with HTML5 parsing rules.
Overview
SwiftSoup is a Swift library for parsing HTML from strings, files, or URLs and working with the resulting document tree. Its API blends DOM-style navigation, CSS selectors, and jQuery-like conveniences for querying and editing nodes.
The parser follows the WHATWG HTML5 specification so output mirrors modern browser structures even for messy markup. Utilities clean user HTML with whitelists to reduce XSS risk and can pretty-print serialized output.
Packages ship through CocoaPods, Carthage, and Swift Package Manager for use on macOS, iOS, tvOS, watchOS, and Linux targets.
Key features
- HTML5-compliant parsing
- CSS selector queries
- DOM traversal and edits
- XSS-oriented sanitization
- Clean HTML output
- URL and file inputs
- Swift Package Manager support
- Cross-platform Swift API
Use cases
- Scraping HTML in Swift apps
- Sanitizing user-generated HTML
- Server-side HTML parsing on Linux
- Extracting data with selectors