0

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>

文字列「pat hardy Memorial」にアクセスするにはどうすればよいですか?

4

2 に答える 2

1

私は間違っているかもしれませんが、問題は、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-08T21:14:14.877 に答える
0

これで済むはず…

for(TFHppleElement* element in linkedNames) {

    NSString* label = [element content];
}
于 2012-12-08T21:47:15.420 に答える