2013-09-25 109 views
0

我使用@"document.getElementsByClassName('entry-content')[0].innerHTML";提取了一個html字符串,並且我已成功獲取HTML響應,並將其存儲在字符串中,問題是我需要刪除名爲「集合形式」的字符串的HTML響應。你們可以幫我。下面是代碼。如何在UIWebview中刪除html字符串中的div標籤

-(void)webViewDidFinishLoad:(UIWebView *)webView1 { 
    NSLog(@"finish"); 
    [activity hide:YES]; 
    NSString *app; 

    if (currentPage == 3) 
    [email protected]"<style>table {font-size:10px;}</style>"; 
    else [email protected]"<style>table {font-size:10px;}</style>"; 

    NSString *temp1 = @"document.getElementsByClassName('entry-content')[0].innerHTML; " ; 

    NSString *class =[webView1 stringByEvaluatingJavaScriptFromString:temp1]; 

    NSString *localString = [NSString stringWithFormat:@"%@%@",class,app]; 

    [webView1 loadHTMLString:localString baseURL:nil]; 

    webView.hidden = NO; 
    webView.delegate =nil; 
} 

回答

0

一種解決方案是呼叫js代碼的內容被加載之後除去該元素。

NSString *jsCommand = [NSString stringWithFormat: 
     @"var element = document.getElementById('%@'); element.parentElement.removeChild(element);", 
     @"id2", 
]; 
[webView stringByEvaluatingJavaScriptFromString:jsCommand] 

,這是另一種方式,如果你想使用JavaScript

How to remove tag from html with JavaScript in iphone UIWebView

+0

這將是適用於類呢? –