iPhone SDK:hpple html 解析器 SIGABRT

发布于 12-09 01:23 字数 696 浏览 5 评论 0原文

我有以下代码:

-(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年2024-12-16 01:23:43

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文