3

I'm very new with objective-c but good with regular C and I'm looking into iPhone development. Right now all my nodes in schools grading system are nil I know they are at the right xPath because //table[@class='grid']/tbody/tr[4]/td[16] show up correctly in Firefox xPath checker plugin. I know the NSData I receive from the webpage is correct because I NSlogged it. But still for some reason I still end up with nil Nodes .

Course2 *fillCourse(int row){

    NSURL *CUrl = [NSURL URLWithString:@"MY SCHOOL SITE HERE"];
    NSData *CHtmlData = [NSData dataWithContentsOfURL:CUrl];

    TFHpple *StuffParser = [TFHpple hppleWithHTMLData:CHtmlData];
    NSString *XpathQ = @"//table[@class='grid']/tbody/tr[5]/td[16]/a";
    NSArray *tutorialsNodes = [StuffParser searchWithXPathQuery:XpathQ];
    /*
    for(TFHppleElement *string in tutorialsNodes){
        NSLog(@"%@",[element content]);

    }
     */
    NSString *XpathQ2 = @"//table[@class='grid']/tbody/tr[5]/td[16]/a";
    NSArray *tutorialsNodes2 = [StuffParser searchWithXPathQuery:XpathQ2]; 

    Course2 *COUR = [[Course2 alloc] init];
    //  NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
    for (TFHppleElement *element in tutorialsNodes) {
        COUR.grade = [element content];
        COUR.teacherPage = [NSURL URLWithString:[element objectForKey:@"href"]];
    }
    for (TFHppleElement *element2 in tutorialsNodes2) {
       COUR.Class = [[element2 firstChild] content];
    }

    return COUR;
}
joce
  • 9,624
  • 19
  • 56
  • 74
Nxtmind
  • 57
  • 8

1 Answers1

1

Try removing tbody from your XPath query. I.e., make it look like //table[@class='grid']/tr[4]/td[16]. I also had similar problem with Hpple and I had to remove all tbody's.

VolenD
  • 3,592
  • 18
  • 23