ChristianPraiss / Osmosis

Web-Scraping with Swift made easy
MIT License
17 stars 2 forks source link

Osmosis - Swift Scrapping

Carthage CI Status Version License Platform

Description

Osmosis makes web scraping using Swift easy. With Osmosis you can quickly parse and transform any website to use its data in your app. It is based on the node.js module node-osmosis

Usage

    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 supports both XPath and CSS selectors.

Installation

Osmosis is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Osmosis"

Author

Christian Praiß, christian_praiss@icloud.com

License

Osmosis is available under the MIT license. See the LICENSE file for more info.