【问题标题】:TFHpple only parse texts before <br> tagTFHpple 只解析 <br> 标签之前的文本
【发布时间】:2013-02-18 23:12:30
【问题描述】:

这是 HTML:

<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>

这是我的代码:

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;

我想解析 &lt;p id="content"&gt;&lt;/p&gt; 之间的所有文本,而不需要 &lt;br&gt;

谁能帮帮我?

【问题讨论】:

    标签: objective-c hpple


    【解决方案1】:
     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”标签! 就是这样!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2016-02-14
      • 1970-01-01
      相关资源
      最近更新 更多