0

我有一组 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 提要文章网页提供的,并且<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。

4

1 回答 1

2

请使用此查询查找所有

给定元素内的元素。 div[@id='content_text']

于 2014-05-06T10:19:10.663 回答