2012-12-08 76 views
0

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

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

对信息的索里的代码是:

<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> 

我怎么“苦命拍纪念”访问字符串?

回答

1

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

编辑:好吧,这会给你带有pdf格式的事件标签,包括pat hardy纪念。

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

+0

我没有试图让PDF文件,我只想标签。链接是http://www.nhara.org/scored_races-2013.htm – user1883873

0

这应该这样做...

for(TFHppleElement* element in linkedNames) { 

    NSString* label = [element content]; 
}