[英]How can i get the contents in UIWebview in ios
我的viewcontroller中有一个uiwebview,用于显示epub内容,如何从UIWebView的NSString中获取该内容? 此代码对我不起作用
NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];
试试这个:
NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];//may be `"document.body.innerText;"`
使用此委托确保在加载Web视图之前显示内容:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if(!webView.isLoading){
//if you need to get all ressources
NSString html=[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
//if you need just the content of Body
NSString html=[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.