Question

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 :-)

Was it helpful?

Solution

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);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top