2013-04-06 51 views
0

我有HTML頁面的響應節點解析與

 `<cite>www.<b>apple</b>.com/in/</cite>` 

我使用圖書館https://github.com/topfunky/hpple/blob/master/

  TFHppleElement * element6 = [childrenArr5 objectAtIndex:0]; 
      NSArray * arr = [element6 childrenWithTagName:@"cite"]; 
      NSLog(@"arr:%@ cnt:%d",arr,[arr count]); 
      TFHppleElement * element7 = [arr objectAtIndex:0]; 
      NSString * cite = [element7 text]; 
      NSLog(@"cite:%@",cite); 

,但我沒有得到整個文本,它只是搶來解析這個「萬維網。」來自,請建議一些內容以獲取標籤中的全部文本。

回答

0

文字只給你一個元素的文字。它忽略了可能存在的任何孩子。

    • TextNode:WWW。
    • b
      • TextNode:蘋果
    • TextNode:.COM /中/

得到一個城市的標籤忽略任何標籤之間我認爲像下的所有文字這應該做

@interface THppleElement (textInlcudingChildren) 
- (NSString*)textInlcudingChildren; 
@end 

@implementation THppleElement (textInlcudingChildren) 
- (NSString*)textInlcudingChildren { 
    NSMutableString *txt = self.text; 
    for(id child in self.children) 
     [txt appendString:[child textInlcudingChildren]]; 
    return txt; 
} 
@end 
... 

NSString * text = [element7 textInlcudingChildren]; 
NSLog(@"%@", text); 
+0

使內聯類別,所以沒有瓜爾但它應該工作 – 2013-04-06 12:11:52

+0

謝謝,我想用上面的代碼。 – bhavin 2013-04-06 12:28:03