SwiftSoup is a pure Swift HTML parser that combines DOM traversal, CSS selectors, and jQuery-like methods for parsing and manipulating HTML across macOS, iOS, tvOS, watchOS, and Linux.
The tool solves the problem of extracting and transforming data from HTML documents in Swift applications. It parses HTML according to the WHATWG HTML5 specification, ensuring that malformed or messy HTML is handled the same way modern browsers handle it, producing a reliable parse tree. The library supports parsing from URLs, files, or strings, and includes automatic format detection that switches between HTML and XML parsing based on whether an XML declaration is present in the input.
SwiftSoup suits projects that need to scrape web content, extract structured data from HTML, or manipulate HTML dynamically within Swift applications. It is particularly useful for server-side Swift applications on Linux as well as iOS and macOS apps. The tool includes features for finding and extracting data via DOM traversal or CSS selectors, modifying elements and attributes, sanitizing user-submitted content with a whitelist to prevent XSS attacks, and generating clean HTML output. It handles both well-formed and malformed HTML reliably.
The project maintains active support across multiple dependency managers including CocoaPods, Carthage, and Swift Package Manager. Development includes a lightweight profiler gated by a compile-time flag and a CLI harness for parsing benchmarks, indicating attention to performance characteristics. The codebase supports both recent Swift versions and maintains compatibility with older Swift releases where applicable.