iphone - TFHpple - getting element HTML without element's tags? -
i'm parsing html , need innerhtml of <body />
. i'm doing way:
tfhpple *doc = [[tfhpple alloc] initwithhtmldata:[nsdata datawithcontentsoffile:sectionfilepath]]; tfhppleelement *body = [doc searchwithxpathquery:@"//body"][0]; nsstring *bodyhtml = body.raw;
however returns:
<body>stuff inside body</body>
instead of just:
stuff inside body
question: there way purely inner html of element, excluding own tags?
i came method, feel i'm reinventing wheel here. method quite slow.
tfhppleelement *child; for(int = 0; i<body.children.count; i++){ child = (tfhppleelement*)body.children[i]; if(child.raw != nil) [bodyhtml appendstring:child.raw]; else if(child.content != nil) [bodyhtml appendstring:child.content]; }
try this...
nsurl *url = [nsurl urlwithstring: url_here]; nsdata *htmldata = [nsdata datawithcontentsofurl:url]; tfhpple *parser = [tfhpple hpplewithhtmldata:htmldata]; nsstring *xpathquerystring = @"//body"; nsarray *nodes = [parser searchwithxpathquery:xpathquerystring]; (tfhppleelement *element in nodes) { lable.text = [[element firstchild] content]; }
Comments
Post a Comment