[英]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.