2013-04-06 52 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