John Iannuzzi
John Iannuzzi

Reputation: 11

How to retrieve text from a website with Swift

New to coding so spare me if this is rather simple. I'm trying to download text from a web page in swift, like from a news article, Wikipedia or something. I can get the HTML or JSON, but I cannot extract the text as a string. Thanks!

Upvotes: 0

Views: 1783

Answers (1)

Scinfu
Scinfu

Reputation: 1131

try SwiftSoup

Example:

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("")
}catch{
    print("")
}

Upvotes: 1

Related Questions