This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do{ | |
let html: String = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>"; | |
let doc: Document = try! SwiftSoup.parse(html) | |
let link: Element = try! doc.select("a").first()! | |
let text: String = try! doc.body()!.text(); // "An example link" | |
let linkHref: String = try! link.attr("href"); // "http://example.com/" | |
let linkText: String = try! link.text(); // "example"" | |
let linkOuterH: String = try! link.outerHtml(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do{ | |
let html = "<html><head><title>First parse</title></head>" | |
+ "<body><p>Parsed HTML into a doc.</p></body></html>" | |
let doc: Document = try SwiftSoup.parse(html) | |
return try doc.text() | |
}catch Exception.Error(let type, let message){ | |
print(message) | |
}catch{ | |
print("error") | |
} |