All Projects → tid-kijyun → Kanna

tid-kijyun / Kanna

Licence: mit
Kanna(鉋) is an XML/HTML parser for Swift.

Programming Languages

swift
15916 projects
shell
77523 projects
HTML
75241 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Kanna

html2any
🌀 parse and convert html string to anything
Stars: ✭ 43 (-98.07%)
Mutual labels:  html-parser, xml-parser
Posthtml
PostHTML is a tool to transform HTML/XML with JS plugins
Stars: ✭ 2,737 (+22.9%)
Mutual labels:  html-parser, xml-parser
Webpageparser
A delightful xml and html parsing relish for iOS
Stars: ✭ 236 (-89.4%)
Mutual labels:  html-parser, xml-parser
Hquery.php
An extremely fast web scraper that parses megabytes of invalid HTML in a blink of an eye. PHP5.3+, no dependencies.
Stars: ✭ 295 (-86.75%)
Mutual labels:  html-parser, xml-parser
Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (-12.93%)
Mutual labels:  html-parser, xml-parser
Oga
Read-only mirror of https://gitlab.com/yorickpeterse/oga
Stars: ✭ 1,147 (-48.5%)
Mutual labels:  html-parser, xml-parser
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (-59.86%)
Mutual labels:  html-parser, xml-parser
Sax Wasm
The first streamable, fixed memory XML, HTML, and JSX parser for WebAssembly.
Stars: ✭ 89 (-96%)
Mutual labels:  html-parser, xml-parser
Lua Gumbo
Moved to https://gitlab.com/craigbarnes/lua-gumbo
Stars: ✭ 116 (-94.79%)
Mutual labels:  html-parser
Xml2lua
XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
Stars: ✭ 150 (-93.26%)
Mutual labels:  xml-parser
Myhtml
Fast C/C++ HTML 5 Parser. Using threads.
Stars: ✭ 1,512 (-32.11%)
Mutual labels:  html-parser
Harser
Easy way for HTML parsing and building XPath
Stars: ✭ 135 (-93.94%)
Mutual labels:  html-parser
Minimize
Minimize HTML
Stars: ✭ 150 (-93.26%)
Mutual labels:  html-parser
Save For Offline
Android app for saving webpages for offline reading.
Stars: ✭ 114 (-94.88%)
Mutual labels:  html-parser
Parser
📜 XML Document Parser for PHP
Stars: ✭ 171 (-92.32%)
Mutual labels:  xml-parser
Floki
Floki is a simple HTML parser that enables search for nodes using CSS selectors.
Stars: ✭ 1,642 (-26.27%)
Mutual labels:  html-parser
Wxmlify
一个轻量快速的插件,帮助你在微信小程序中显示富文本编辑器生成的HTML。
Stars: ✭ 93 (-95.82%)
Mutual labels:  html-parser
Unhtml.rs
A magic html parser
Stars: ✭ 180 (-91.92%)
Mutual labels:  html-parser
Pywebcopy
Python library to mirror webpage and websites.
Stars: ✭ 156 (-93%)
Mutual labels:  html-parser
Nsoup
NSoup is a .NET port of the jsoup (http://jsoup.org) HTML parser and sanitizer originally written in Java
Stars: ✭ 145 (-93.49%)
Mutual labels:  html-parser

Kanna(鉋)

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

It was inspired by Nokogiri(鋸).

CI Platform Cocoapod Carthage compatible Swift Package Manager MIT License

ℹ️ Documentation

Features

  • XPath 1.0 support for document searching
  • CSS3 selector support for document searching
  • Support for namespaces
  • 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
    CSS.swift
    libxmlHTMLDocument.swift
    libxmlHTMLNode.swift
    libxmlParserOption.swift
    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 the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].