我有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);
但是我没有收到整篇文章,只是抓住了“www”。来自,请建议在标签内获取整个文本。
答案 0 :(得分:1)
text仅为您提供ONE元素的文本。它忽略了可能存在的任何孩子。
要获取城市标签下的所有文字,忽略其间的任何标签,我认为应该这样做
@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);