How to get all HTML elements in UIWebView

2019-07-25 11:22发布

I have loaded an UIWebView with .rtf file.

Now, I want to get all HTML elements or elements present inside the UIWebView. Is there any method available to get it?

Thanks for your answers.

标签: ios uiwebview
2条回答
Root(大扎)
2楼-- · 2019-07-25 11:39

You can get all of the HTML content of your UIWebView with the call:

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

After this it's up to you.

查看更多
看我几分像从前
3楼-- · 2019-07-25 11:51

You could use JavaScript to get the element...

NSString *javaScript = @"document.getElementById( YOU ID );";
NSString *response = [webView stringByEvaluatingJavaScriptFromString:javaScript];

Hope that helps...

查看更多
登录 后发表回答