获取加载的UIWebView的HTML源代码 [英] Getting the HTML source code of a loaded UIWebView

查看:117
本文介绍了获取加载的UIWebView的HTML源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 UIWebView HTML 源代码并将其存储在的NSString

How can I get the HTML source code of a UIWebView and store it in NSString?

推荐答案

如果你想要一个已经加载的webview的源代码,你可以像这样得到它:

If you want the source code of an already loaded webview, you can get it like this:

    NSString *yourHTMLSourceCodeString = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

更新:上面的方法大部分时间都适用。但我最近处于一种需要所有代码源的情况,而不仅仅是身体。

Update: method above works most of the time. But I recently was in a situation where I needed all the code source, not just the body.

以下是更好的方法:

    NSString *yourHTMLSourceCodeString = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];       

(它不会重新加载网页视图)。

(It won't reload the webview).

这篇关于获取加载的UIWebView的HTML源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆