我的viewcontroller中有一个用于显示epub内容的uiwebview,如何从UIWebView获取NSString中的内容? 这段代码对我不起作用
NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];
答案 0 :(得分:1)
试试这个:
NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];//may be `"document.body.innerText;"`
答案 1 :(得分:0)
使用此委托确保在显示内容之前加载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"];
}
}