1

I'm trying to get the title tag of an HTML, and am using Hpple to parse the HTML. For some reason, I'm getting null when i use this code

    NSURL *Url = self.webview.request.URL;
NSData *HtmlData = [NSData dataWithContentsOfURL:Url];
TFHpple *Parser = [TFHpple hppleWithHTMLData:HtmlData];
NSString *XpathQueryString = @"//head/title";
NSArray *Nodes = [Parser searchWithXPathQuery:XpathQueryString];
self.textfield.text = [NSString stringWithFormat:@"%@|%@", [[[[Nodes objectAtIndex:0] objectForKey:@"nodeChildArray"] objectAtIndex:0] objectForKey:@"nodeContent"], [Url absoluteString]];

when i log the array [Nodes objectAtIndex:0] I get

{
 nodeChildArray =     (
            {
        nodeContent = Google;
        nodeName = text;
    }
);
nodeName = title;
}
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
  • 5
    Just out of curiosity, if all you need to do is get the title, why not just reflect the DOM in JS, via `[UIWebView stringByEvaluatingJavaScriptFromString:@"(function() { return document.title })();"]`? Or do you think you'll need to parse more out of your document? – KevinH Feb 03 '13 at 02:18
  • good point there, much easier than what i was trying. thanks – Chris Loonam Feb 03 '13 at 02:20

0 Answers0