javascript - Get text of span without ID -
i'm trying piece of text span line has not id. using xcode , swift 3.
here's line:
<span class="name">peter red</span> i tried not work:
var name = webview.evaluatejavascript("document.queryselector('.name').innerhtml")         print("name \(name)") i tried using .innertext, .textcontent , outertext console prints name ()
the evaluatejavascript(_:completionhandler:) instance method expects 2 parameters.
func evaluatejavascript(_ javascriptstring: string,        completionhandler: ((any?, error?) -> void)? = nil) you missing completionhandler, run once script evaluation completes or fails.
try following:
 webview.evaluatejavascript("document.queryselector('.name').innerhtml") { (name, error) in         if error == nil {            print("name \(name)")         }     } 
Comments
Post a Comment