Popularity
8.6
Stable
Activity
6.3
-
2,374
44
220

Code Quality Rank: L3
Programming language: Swift
License: MIT License
Tags: Network     HTML    
Latest version: v5.2.3

Kanna alternatives and similar libraries

Based on the "HTML" category.
Alternatively, view Kanna alternatives based on common mentions on social networks and blogs.

  • SwiftSoup

    SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
  • WKZombie

    WKZombie is a Swift framework for iOS/OSX to navigate within websites and collect data without the need of User Interface or API, also known as Headless browser. It can be used to run automated tests / snapshots and manipulate websites using Javascript.
  • The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
    Promo
  • Ji

    6.7 0.6 L5 Kanna VS Ji
    an XML/HTML parser for Swift.
  • ZMarkupParser

    ZMarkupParser is a pure-Swift library that helps you convert HTML strings into NSAttributedString with customized styles and tags.
  • KJNetworkPlugin

    ๐ŸŽกA lightweight but powerful Network library. Network Plugin, Support batch and chain operation. ๆ’ไปถๆœบๅˆถใ€ไธŠไผ ใ€ไธ‹่ฝฝใ€ๆ‰น้‡ใ€้“พๅผ็ฝ‘็ปœๆžถๆž„

Do you think we are missing an alternative of Kanna or a related project?

Add another 'HTML' Library

README

Kanna(้‰‹)

Kanna(้‰‹) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!).

It was inspired by Nokogiri(้‹ธ).

Build Status Platform Cocoapod Carthage compatible Swift Package Manager Reference Status

:information_source: Documentation

Features

  • [x] XPath 1.0 support for document searching
  • [x] CSS3 selector support for document searching
  • [x] Support for namespaces
  • [x] Comprehensive test suite

Installation for Swift 5

CocoaPods

Add the following to your Podfile:

use_frameworks!
pod 'Kanna', '~> 5.2.2'

Carthage

Add the following to your Cartfile:

github "tid-kijyun/Kanna" ~> 5.2.2

For xcode 11.3 and earlier, the following settings are required.

  1. In the project settings add $(SDKROOT)/usr/include/libxml2 to the "header search paths" field

Swift Package Manager

  1. Installing libxml2 to your computer:
// macOS: For xcode 11.3 and earlier, the following settings are required.
$ brew install libxml2
$ brew link --force libxml2

// Linux(Ubuntu):
$ sudo apt-get install libxml2-dev
  1. Add the following to your Package.swift:
// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "YourProject",
    dependencies: [
        .package(url: "https://github.com/tid-kijyun/Kanna.git", from: "5.2.2"),
    ],
    targets: [
        .target(
            name: "YourTarget",
            dependencies: ["Kanna"]),
    ]
)
$ swift build

Note: When a build error occurs, please try run the following command:

// Linux(Ubuntu)
$ sudo apt-get install pkg-config

Manual Installation

  1. Add these files to your project:
    [Kanna.swift](Source/Kanna.swift)
    [CSS.swift](Source/CSS.swift)
    [libxmlHTMLDocument.swift](Source/libxml/libxmlHTMLDocument.swift)
    [libxmlHTMLNode.swift](Source/libxml/libxmlHTMLNode.swift)
    [libxmlParserOption.swift](Source/libxml/libxmlParserOption.swift)
    [Modules](Modules)
  2. In the target settings add $(SDKROOT)/usr/include/libxml2 to the Search Paths > Header Search Paths field
  3. In the target settings add $(SRCROOT)/Modules to the Swift Compiler - Search Paths > Import Paths field

Installation for swift 4

Installation for swift 3

Synopsis

import Kanna

let html = "<html>...</html>"

if let doc = try? HTML(html: html, encoding: .utf8) {
    print(doc.title)

    // Search for nodes by CSS
    for link in doc.css("a, link") {
        print(link.text)
        print(link["href"])
    }

    // Search for nodes by XPath
    for link in doc.xpath("//a | //link") {
        print(link.text)
        print(link["href"])
    }
}
let xml = "..."
if let doc = try? Kanna.XML(xml: xml, encoding: .utf8) {
    let namespaces = [
                    "o":  "urn:schemas-microsoft-com:office:office",
                    "ss": "urn:schemas-microsoft-com:office:spreadsheet"
                ]
    if let author = doc.at_xpath("//o:Author", namespaces: namespaces) {
        print(author.text)
    }
}

Donation

If you like Kanna, please donate via GitHub sponsors or PayPal.
It is used to improve and maintain the library.

License

The MIT License. See the LICENSE file for more information.


*Note that all licence references and agreements mentioned in the Kanna README section above are relevant to that project's source code only.