Osmosis 让使用 Swift 进行网络渗透变得简单。通过 Osmosis,您可以快速解析并将任何网站转换为在您的应用程序中使用数据的格式。它基于 node.js 模块 node-osmosis
Osmosis()
// Get the website at the given url
.get(url)
// Find all elements matching the selector and execute the following actions on them
.find(OsmosisSelector(selector: "#dailyScore tr.valid"), type: .CSS)
// Populate the information you want from the dict
.populate([
OsmosisPopulateKey.Single("points") : OsmosisSelector(selector: "td:nth-child(2)"),
OsmosisPopulateKey.Single("aircraft"): OsmosisSelector(selector: "#tt_aircraft b"),
OsmosisPopulateKey.Single("takeOffLocation"): OsmosisSelector(selector: ".hlinfo > b:last-child"),
OsmosisPopulateKey.Single("pilot"): OsmosisSelector(selector: ".hltitel a")]
, type: .CSS)
// Get the parsed information
.list { (var dict) -> Void in
// Use the parsed dict here
print(dict)
}
// Start the operations
.start()
Osmosis 支持 XPath 和 CSS 选择器。
Osmosis 通过 CocoaPods 可用。要安装它,只需将以下行添加到您的 Podfile 中
pod "Osmosis"
Christian Praiß,[email protected]
Osmosis 可在 MIT 许可下获得。有关更多信息,请参阅 LICENSE 文件。