سؤال

I have the following code:

-(void)getHTMLData {
    NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"];
    TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:data];

    //Get all the cells of the 2nd row of the 3rd table 
    NSArray *elements  = [xpathParser search:@"//table[3]/tr[2]/td"]; // "//a" -- all a tags

    TFHppleElement *element = [elements objectAtIndex:0];
    NSString *content = [element content];  
    [xpathParser release];
    [data release];

    NSLog(@"tagName:%@", content);

}

but anytime it runs, it stops at the line with a SIGABRT error:

NSArray *elements  = [xpathParser search:@"//table[3]/tr[2]/td"];

Any help is much appreciated.

هل كانت مفيدة؟

المحلول

user170317 gave you the answer mate, the TFHpple class changed between the version you downloaded and the example you're using (however you'll find an example in the download which does work, kinda)

reason for this is that the 'search' method is now 'searchWithXPathQuery', change it to that and it'll work. If you get null after it runs it's because you're not targeting the right child node, but thats another question

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top