the Code:
NSString *linkStr=@"http://www.voanews.com/content/obama_pledges_aid_to_drought_stricken_farmers/1484380.html";
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:linkStr]];
// Create parser
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:data];
//Get all the cells of the 2nd row of the 3rd table
NSArray *elements = [xpathParser searchWithXPathQuery:@"//p[@class='article_date']"];
// Access the first cell
if ([elements count] > 0)
{
TFHppleElement *element = [elements objectAtIndex:0];
// Get the text within the cell tag
NSString *content = [element content];
NSLog(@"VOA = %@",content); //Result : print NULL
}
[xpathParser release];
[data release];
but I use the XPath Helper query the “//p[@class=’article_date’]” ,it’s ok, but in my code the content is null
Running your code example, if I change
[element content]for[element text], my output is:In its Github repo, they mention (at USAGE section):
And looking at the source code of the CONTENT method it uses
objectForKey, whereTFHppleContentKey = "nodeContent". See:It seems that it’s safe to use
[element text]instead of[element content]in your example.I hope it helps.