Skip to content

Instantly share code, notes, and snippets.

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();
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")
}