Contents

aporat/AlamofireSwiftSoup

Alamofire extension for serialize SwiftSoup HTML documents'

πŸ“¦ 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.

Package Metadata

Repository: aporat/AlamofireSwiftSoup

Stars: 3

Forks: 0

Open issues: 1

Default branch: main

Primary language: swift

License: MIT

README: README.md