Simplest way to do this (works for this specific case):
webView.evaluateJavaScript("document.getElementsByTagName('pre')[0].innerHTML", completionHandler: { (res, error) in
if let fingerprint = res {
// Fingerprint will be a string of JSON. Parse here...
print(fingerprint)
}
})
Possibly better way to do this:
So .innerHTML
returns HTML, not a JSON header. JSON headers are notoriously difficult to grab with WKWebView
, but you could try this method for that. First set:
webView.navigationDelegate = self
And then in the WKNavigationDelegate
method:
public func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
let res = navigationResponse.response as! HTTPURLResponse
let header = res.allHeaderFields
print(header)
}