我有一组HTML代码,在这里:
<div id="content_text">
<p>Year 11 students will be making their course selections online this year.
</p>
<p>Information about this system has been made available through Tutor sessions. Each student will have an individual password. Once subject selections have been made students are to print out a copy of their choices and then have this form signed by themselves, their parent and their Tutor. Forms are to be completed by 22 August. Course books can be borrowed from the Library or are available online.
现在我的问题是,这是来自RSS FEED文章网页,在这一个<p>
中可能有1个甚至11个<div id="content_text">
个标签。如何获取此分隔符中的所有<p>
并将其格式化为UITextField?
我目前正在使用XPathQuery
,顺便说一句,所以目前我的解析看起来像这样:
NSData *tutorialsHtmlDataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:_storyLink]];
TFHpple *tutorialsParserTwo = [TFHpple hppleWithHTMLData:tutorialsHtmlDataTwo];
NSString *tutorialsXpathQueryStringTwo = @"//div[@id='content_text']/p";
NSArray *tutorialsNodesTwo = [tutorialsParserTwo searchWithXPathQuery:tutorialsXpathQueryStringTwo];
NSMutableArray *newTutorialsTwo = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodesTwo) {
Tutorial *tutorialTwo = [[Tutorial alloc] init];
[newTutorialsTwo addObject:tutorialTwo];
tutorialTwo.title = [[element firstChild] content];
_rssBody.text = [NSString stringWithFormat:@"%@", [[element firstChild] content]];
}
因为你可以看到它只会解析第二行。任何帮助表示赞赏。
谢谢,SebOH。
答案 0 :(得分:2)
请使用此查询查找给定元素中的所有
元素。
div[@id='content_text']