Reading HTML content from a UIWebView

前端 未结 10 2551
感动是毒
感动是毒 2020-11-22 13:47

Is it possible to read the raw HTML content of a web page that has been loaded into a UIWebView?

If not, is there another way to pull raw HTML content f

10条回答
  •  攒了一身酷
    2020-11-22 14:29

    UIWebView

    get HTML from UIWebView`

    let content = uiWebView.stringByEvaluatingJavaScript(from: "document.body.innerHTML")
    

    set HTML into UIWebView

    //Do not forget to extend a class from `UIWebViewDelegate` and nil the delegate
    
    func someFunction() {
    
        let uiWebView = UIWebView()
        uiWebView.loadHTMLString("", baseURL: nil)
        uiWebView.delegate = self as? UIWebViewDelegate
    }
    
    func webViewDidFinishLoad(_ webView: UIWebView) {
        //ready to be processed
    }
    

    [get/set HTML from WKWebView]

提交回复
热议问题