首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TFHpple解析链接

TFHpple解析链接
EN

Stack Overflow用户
提问于 2012-12-09 04:27:23
回答 2查看 828关注 0票数 0

如何解析TFhpple中的链接。我的代码返回一个空数组。

代码语言:javascript
复制
NSString *link2=[NSString stringWithFormat:@"/html/body/table/tr[%d]/td[1]/a",i+2];
 NSArray *linkedNames = [xpathParser searchWithXPathQuery:link2];
             NSLog(@"%@", linkedNames);

该信息的源代码为:

代码语言:javascript
复制
 <td style="font-size: 12.0pt; color: black; font-weight: 400; text-decoration: none; text-underline-style: none; font-family: Arial Narrow; font-style: normal; text-align: general; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: 1.0pt solid windowtext; border-top: medium none; border-bottom: 1.0pt solid windowtext; padding-left: 1px; padding-right: 1px; padding-top: 1px; background: #EAF1DD" width="327">
    <a href="race_announcements/12.22.12RA.pdf">Pat Harty Memorial</a></td>

我如何访问字符串“帕特哈迪纪念”?

EN

回答 2

Stack Overflow用户

发布于 2012-12-09 05:14:15

我可能错了,但我认为问题可能是您试图使用xml解析器来解析pdf文件。pdf的实际内容可能不在html中。如果你提供一个链接,我可能会有更多的帮助。干杯。

编辑:好的,这将给你事件的标签与pdf,包括帕特哈迪纪念馆。

代码语言:javascript
复制
NSURL *url = [NSURL URLWithString:@"http://www.nhara.org/scored_races-2013.htm"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
TFHpple *parser = [TFHpple hppleWithHTMLData:urlData];
NSString *propertyXpathQueryString = @"//td/a";
NSArray *propertiesNodes = [parser searchWithXPathQuery:propertyXpathQueryString];

NSMutableArray *list =[[NSMutableArray alloc] init];
NSString *string = [[NSString alloc] init];
for (TFHppleElement *element in propertiesNodes) {

    [list addObject:string];

    string = [[element firstChild] content];


}
for (int i = 0; i < [list count]; i++) {
    NSLog([list objectAtIndex:i]);
}
}

另外,这里有一个很好的教程http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

票数 1
EN

Stack Overflow用户

发布于 2012-12-09 05:47:15

这个应该可以..。

代码语言:javascript
复制
for(TFHppleElement* element in linkedNames) {

    NSString* label = [element content];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13781609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档