AlamofireSwiftSoup
安装
推荐通过 CocoaPods 包管理器安装 AlamofireSwiftSoup,因为它提供了灵活的依赖管理以及简单易用的安装。
如果还没有安装 CocoaPods,请先安装。
$ [sudo] gem install cocoapods
$ pod setup
编辑您的 Podfile 并添加 AlamofireSwiftSoup
$ edit Podfile
platform :ios, '12.0'
pod 'AlamofireSwiftSoup'
将安装包加入您的 Xcode 项目
$ pod install
用法
import AlamofireSwiftSoup
AF.request("https://httpbin.org/").responseSwiftSoupHTML { dataResponse in
switch dataResponse.result {
case .failure(let error):
debugPrint(error)
case .success(let document):
if let scriptElement = try? document.select("title").first(), let titleString = try? scriptElement.html() {
debugPrint(titleString)
}
}
}