I'm trying to scrape data from a website, and the data I want is in a span tag. So far, what I've done is:
var str: Any?
webView.evaluateJavaScript("innerDoc.getElementById(spanId).innerHTML", completionHandler:
{ (html: Any?, error: Error?) in
str = html
})
print(str)
But when I do this I just get nil. If I put print(html)
in place of str = html
I get the output I want.
What am I doing wrong here? Why can't I store that value in a variable?