swiftmacoshtml-parsingwkwebviewswiftsoup

SwiftSoup Parse From evaluateJavaScript


I'm trying to use SwiftSoup to parse HTML from a webpage. I'm using evaluateJavaScript with "document.getElementById(\"fieldsort\").innerHTML" as my JavaScript. I'm not using String(contentsOf: URL) because that doesn't return the HTML for the elements of the page.

I am saving the string as str, and I'm using SwiftSoup.parse(str) to parse it. However, when I print the value of the Document that is created, it is empty. How do I correctly parse this and is there a better, more efficient way to use SwiftSoup with a webpage?


Solution

  • For some reason, parsing as XML solved it.