UIWebView get HTML Source

2019-05-06 16:53发布

I am trying to get the HTML source of a UIWebView without re-downloading it again (a.k.a. do another download, such as [NSData dataWithContentsOfURL:(NSURL*)URL] or launching an NSURLRequest. Browsing the UIWebView header and documentation, there seems to be no way of accessing the current loaded NSData of the source. Am I missing something ?

2条回答
Root(大扎)
2楼-- · 2019-05-06 17:29

UIWebView can execute javascript code, so this can work it out.

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
查看更多
3楼-- · 2019-05-06 17:36

The inverse should do what you want. That is, load the URL into an NSData object and then load the UIWebView from that object using – loadData:MIMEType:textEncodingName:baseURL:

查看更多
登录 后发表回答