简体   繁体   English

如何在iOS中的UIWebview中获取内容

[英]How can i get the contents in UIWebview in ios

I have a uiwebview in my viewcontroller which is used to display the epub contents ,How can i get that contents in NSString from UIWebView? 我的viewcontroller中有一个uiwebview,用于显示epub内容,如何从UIWebView的NSString中获取该内容? This code not working for me 此代码对我不起作用

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

试试这个:

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];//may be `"document.body.innerText;"`

Use this delegate to ensure the loading web view before to display content: 使用此委托确保在加载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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM