2012-12-08 2 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); 

정보에 대한 soure 코드는 다음과 같습니다

<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에 없을 수도 있습니다. 링크를 제공하면 도움이 될 것입니다. 건배.

편집 : 음, pat hardy memorial을 포함한 pdfs 이벤트 레이블을 제공합니다.

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]; 
}