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:
- Downloads HTML content using Alamofire
- Parses the raw HTML into a
SwiftSoup.Document - Returns the document in the
responseHTMLcallback
π 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