Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

samlamgithub/Swift-HTML-Parser

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift-HTML-Parser

A swift wrapper around libxml for parsing HTML

Usage

  1. Add HTMLParser.swift, HTMLNode.swift, Swift-HTML-Parser-Bridging-Header.h to your project
  2. In the project settings add "Swift-HTML-Parser-Bridging-Header.h" to the "Objective-C Bridging Header"
  3. In the project settings add "/usr/include/libxml2" to the "header search paths" field
  4. Add libxml2.dylib to ""Link Binary With Libraries"

Example

import Foundation

let html = "<html><head></head><body><ul><li><input type='image' name='input1' value='string1value' class='abc' /></li><li><input type='image' name='input2' value='string2value' class='def' /></li></ul><span class='spantext'><b>Hello World 1</b></span><span class='spantext'><b>Hello World 2</b></span><a href='example.com'>example(English)</a><a href='example.co.jp'>example(JP)</a></body>"

var err : NSError?
var parser     = HTMLParser(html: html, error: &err)
if err != nil {
    println(err)
    exit(1)
}

var bodyNode   = parser.body

if let inputNodes = bodyNode?.findChildTags("b") {
    for node in inputNodes {
        println(node.contents)
    }
}

if let inputNodes = bodyNode?.findChildTags("a") {
    for node in inputNodes {
        println(node.contents)
        println(node.getAttributeNamed("href"))
    }
}

About

A swift wrapper around libxml for parsing HTML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 98.9%
  • Objective-C 1.1%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.