Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scinfu/d456ca7cf3b9fee5b3cefad4afbeee49 to your computer and use it in GitHub Desktop.
Save scinfu/d456ca7cf3b9fee5b3cefad4afbeee49 to your computer and use it in GitHub Desktop.
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