首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TFHpple仅解析<br>标记之前的文本

TFHpple仅解析<br>标记之前的文本
EN

Stack Overflow用户
提问于 2013-03-05 02:46:17
回答 1查看 739关注 0票数 2

这是HTML:

代码语言:javascript
复制
<p id="content">Every Sunday, our Chef proposes a buffet high in color.
<br>
A brunch either classic or on a theme for special events
<br>
Every Sunday at the restaurant
</p>

下面是我的代码:

代码语言:javascript
复制
NSString *u = [[NSString alloc] initWithFormat:@"http//mydomain.com%@", _currentNews.url];
NSURL *url = [NSURL URLWithString:u];
NSData *paHtmlData = [NSData dataWithContentsOfURL:url];

TFHpple *paParser = [TFHpple hppleWithHTMLData:paHtmlData];

NSArray *array = [paParser searchWithXPathQuery:@"//p[@id='content']/text()"];
TFHppleElement *ele= [array objectAtIndex:0];

_currentBody.text = [ele text];
_currentTitle.text = _currentNews.title;

我想在没有<br>的情况下解析<p id="content"></p>之间的所有文本

有谁可以帮我?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-22 16:02:31

代码语言:javascript
复制
 NSString*  webSIteSource=[NSString stringWithContentsOfURL:[NSURL URLWithString:u]encoding:NSUTF8StringEncoding error:nil];

    webSIteSource=  [webSIteSource stringByReplacingOccurrencesOfString:@"<br />"withString:@" "];
    webSIteSource=[webSIteSource stringByReplacingOccurrencesOfString:@"<blockquote>" withString:@" "];
    webSIteSource=[webSIteSource stringByReplacingOccurrencesOfString:@"</blockquote>" withString:@" "];

只需将所有网站内容装入nsstring,然后删除所有"br“标签!就这样!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15208773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档