如何解析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>我如何访问字符串“帕特哈迪纪念”?
发布于 2012-12-09 05:14:15
我可能错了,但我认为问题可能是您试图使用xml解析器来解析pdf文件。pdf的实际内容可能不在html中。如果你提供一个链接,我可能会有更多的帮助。干杯。
编辑:好的,这将给你事件的标签与pdf,包括帕特哈迪纪念馆。
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
发布于 2012-12-09 05:47:15
这个应该可以..。
for(TFHppleElement* element in linkedNames) {
NSString* label = [element content];
}https://stackoverflow.com/questions/13781609
复制相似问题