Skip to content

Commit 01e5094

Browse files
committed
Changed HTMLParser.init argument / Added Sample
Changed init(html: String, inout error: NSError?, encoding : UInt) to init(html: String, encoding : UInt, inout error: NSError?)
1 parent 1593284 commit 01e5094

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Swift-HTML-Parser/HTMLParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class HTMLParser {
6666
}
6767
}
6868

69-
public init(html: String, inout error: NSError?, encoding : UInt) {
69+
public init(html: String, encoding : UInt, inout error: NSError?) {
7070
if html.lengthOfBytesUsingEncoding(encoding) > 0 {
7171
self.htmlString = html
7272
var cfenc : CFStringEncoding = CFStringConvertNSStringEncodingToEncoding(encoding)

Swift-HTML-Parser/main.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
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><div class='box'><span class='dat'><strong content='2014-12-31'>2014/12/31</strong></span><h2>Hoge</h2></div></body>"
3+
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><div class='val'>value1</div><div class='val'>value2</div><div class='box'><span class='dat'><strong content='2014-12-31'>2014/12/31</strong></span><h2>Hoge</h2></div></body>"
44

55
var err : NSError?
66
var parser = HTMLParser(html: html, error: &err)
@@ -24,6 +24,15 @@ if let inputNodes = bodyNode?.findChildTags("a") {
2424
}
2525
}
2626

27+
println(bodyNode?.findChildTagAttr("div", attrName: "class", attrValue: "val")?.contents)
28+
29+
if let inputNodes = bodyNode?.findChildTagsAttr("div", attrName: "class", attrValue: "val") {
30+
for node in inputNodes {
31+
println(node.contents)
32+
}
33+
}
34+
35+
2736
if let path = bodyNode?.xpath("//div[@class='box']") {
2837
for node in path {
2938
println(node.tagName)

0 commit comments

Comments
 (0)