Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse data from webView to use in code

I have a WKWebView in my project which does some operations, after clicking submit inWKWebView it displays JSON data in javaScript that I need to pars in my code.

like image 613
Azza Avatar asked Aug 01 '26 21:08

Azza


2 Answers

Swift 5.1 examples:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        print("redirect didFinish")
        print(webView)
        webView.evaluateJavaScript("document.documentElement.outerHTML.toString()",
                                   completionHandler: { (html: Any?, error: Error?) in
                                    print(html as Any)
        })
    }
like image 180
ikbal Avatar answered Aug 04 '26 14:08

ikbal


You can get source code of your UIWebViewpage.

func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
    webView.evaluateJavaScript("document.getElementsByTagName('html')[0].innerHTML") { innerHTML, error in
        print(innerHTML!)
    }
}
like image 29
Emre Avatar answered Aug 04 '26 14:08

Emre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!