iPhone SDK:hpple html 解析器 SIGABRT
我有以下代码:
-(void)getHTMLData {
NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:data];
//Get all the cells of the 2nd row of the 3rd table
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"]; // "//a" -- all a tags
TFHppleElement *element = [elements objectAtIndex:0];
NSString *content = [element content];
[xpathParser release];
[data release];
NSLog(@"tagName:%@", content);
}
但无论何时运行,它都会在该行停止并出现 SIGABRT 错误:
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"];
非常感谢任何帮助。
I have the following code:
-(void)getHTMLData {
NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:data];
//Get all the cells of the 2nd row of the 3rd table
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"]; // "//a" -- all a tags
TFHppleElement *element = [elements objectAtIndex:0];
NSString *content = [element content];
[xpathParser release];
[data release];
NSLog(@"tagName:%@", content);
}
but anytime it runs, it stops at the line with a SIGABRT error:
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"];
Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

user170317 给了你答案,伙计,TFHpple 类在你下载的版本和你正在使用的示例之间发生了变化(但是你会在下载中找到一个确实有效的示例),
原因是“搜索”方法现在是“searchWithXPathQuery”,将其更改为该值即可工作。如果运行后得到 null,那是因为您没有定位正确的子节点,但这是另一个问题
user170317 gave you the answer mate, the TFHpple class changed between the version you downloaded and the example you're using (however you'll find an example in the download which does work, kinda)
reason for this is that the 'search' method is now 'searchWithXPathQuery', change it to that and it'll work. If you get null after it runs it's because you're not targeting the right child node, but thats another question