print(html)
之后,我得到了没有数据的清晰HTML。
import UIKit
import WebKit
class ViewController: UIViewController,WKNavigationDelegate{
let webView = WKWebView()
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
print("loaded")
webView.evaluateJavaScript("document.documentElement.innerHTML.toString()",
completionHandler: { (html: Any?, error: Error?) in
print(html)
})
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL (string: "https://mobile.bet365.com")
let request = URLRequest (url:url!)
webView.frame = CGRect (x:0,y:0,width:300,height:300)
webView.navigationDelegate = self
webView.load(request)
view.addSubview(webView)
}
}