Created
April 3, 2017 15:39
-
-
Save scinfu/d456ca7cf3b9fee5b3cefad4afbeee49 to your computer and use it in GitHub Desktop.
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(); | |
// "<a href="http://example.com"><b>example</b></a>" | |
let linkInnerH: String = try! link.html(); // "<b>example</b>" | |
}catch Exception.Error(let type, let message){ | |
print(message) | |
}catch{ | |
print("error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment