将多行HTML解析加载到一个Uitextfield中



我有一组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提要文章网页中馈出的,并且在此<div id="content_text">中可能有1个甚至11个<p>标签。我如何在此分隔线中获取所有<p>并将其格式显示为Uitextfield?

我目前正在使用XPathQuery,BTW,所以我的解析看起来像这样:

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。

请使用此查询查找给定元素内部的所有

元素。 div[@id='content_text']

最新更新