1

the part that i am having trouble with reading is this html code:

<div id="main">
<h1>Hvorfor flager busserne i dag?</h1>
<h2>Idag den 26. august flager busserne ikke</h2>

My code in xcode looks like this:

   NSString *tutorialsXpathQueryString1 = @"/html/body/div [@id='main']";
    NSArray *tutorialsNodes1 = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString1];

    for (TFHppleElement * element in tutorialsNodes1) {
        NSLog(@"Link is: %@", [element objectForKey:@"h2"]);
        }

The code are running, but i can't get the text.. I am using Hpple as parser.

I really need some help, so everything is appriciated :-)

Charlie Brown
  • 2,817
  • 2
  • 20
  • 31
JMIT
  • 169
  • 2
  • 15

1 Answers1

1

To get a child element, you need to use a different method, and then access its text property.

for (TFHppleElement * element in tutorialsNodes1) {
    NSLog(@"Link is: %@", [element firstChildWithTagName:@"h2"].text);
    }
Charlie Brown
  • 2,817
  • 2
  • 20
  • 31
  • Thank You! Please note for any other people out there to be sure to use the latest version of 'hpple' else you are going to get an error from the firstChildWithTagName ;) – JMIT Sep 06 '13 at 21:02