iosobjective-chpple

Objective C - hpple getting text from inside TR tags


First time here.

Im attempting to build a Iphone app that pulls a single string from a HTML table on a website using hpple, The example of the website is here: http://tsy.acislive.com/pip/stop_simulator_title.asp?naptan=37020349&pscode=22&dest=&offset=1

and the code of the website:

<body class="ss_title">
<table class=piptitle cellpadding='0' cellspacing='0' width="100%"><tr><td align="center" valign="middle">Tannery Street - 02:32 (+1h)</td></tr></table>
</body>

I have tried the following method inside my app to get the text "Tannery Street - 02:32 (+1h):

-(void)loadTitleTable{
    NSLog(@"Load Title Method Called Successfully");

                  NSData *htmlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://tsy.acislive.com/pip/stop_simulator_title.asp?naptan=37020349&pscode=22&dest=&offset=1"]];
                  TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
                  NSArray *elements  = [xpathParser searchWithXPathQuery:@"//tr/td"];
                  TFHppleElement *element = [elements objectAtIndex:0];
                  NSString *myTitle = [[element firstChild] content];
                  NSLog(myTitle);
                  _stopNOlabel.text = myTitle;
    NSLog(@"Array: %@", elements);
}

I have tried outputting the array using NSLog and this is what the array outputs:

Array: ( "{\n nodeAttributeArray = (\n {\n attributeName = align;\n nodeContent = center;\n },\n {\n attributeName = valign;\n nodeContent = middle;\n }\n );\n nodeName = td;\n raw = \"\";\n}" )

I hope somebody here will be able to help me resolve this and set the label to the text string.

Thanks. Damien


Solution

  • Found the best way to do this instead of using Happle is to use a web backend and use JSON data from that rather than scraping in HTML.