AlamofireSwiftSoup

2.1.0

Alamofire extension for serialize SwiftSoup HTML documents'
aporat/AlamofireSwiftSoup

What's New

2.1.0

2025-08-24T16:50:55Z

AlamofireSwiftSoup

A lightweight extension that combines Alamofire and SwiftSoup for easy HTML parsing from web requests.

GitHub Actions Workflow Status codecov

📦 Installation

Swift Package Manager

Add the following to your Package.swift dependencies:

.package(url: "https://github.com/your-username/AlamofireSwiftSoup.git", from: "1.0.0")

And add "AlamofireSwiftSoup" to your target dependencies.


✅ Requirements

  • iOS 15+ / macOS 12+ / tvOS 13+
  • Swift 5.9+
  • Alamofire 5.x
  • SwiftSoup 2.x

🚀 Usage

import Alamofire
import AlamofireSwiftSoup

AF.request("https://example.com").responseHTML { response in
    switch response.result {
    case .success(let document):
        if let title = try? document.title() {
            print("Page title:", title)
        }
    case .failure(let error):
        print("Failed to parse HTML:", error)
    }
}

📘 How It Works

This package adds a custom Alamofire response serializer that:

  1. Downloads HTML content using Alamofire
  2. Parses the raw HTML into a SwiftSoup.Document
  3. Returns the document in the responseHTML callback

📚 Example

AF.request("https://news.ycombinator.com").responseHTML { response in
    if let document = try? response.result.get() {
        let links = try? document.select("a.storylink")
        links?.forEach { print(try? $0.text()) }
    }
}

🛠 License

MIT License. See LICENSE for details.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun Oct 26 2025 21:03:52 GMT-0900 (Hawaii-Aleutian Daylight Time)